#include "Resource.h"
#include "String.h"
#include "SharedPtr.h"
#include "ResourceManager.h"
#include "Database/DatabaseEnv.h"
#include "StringConverter.h"
#include "NGLog.h"
#include "Character.h"
#include "CharManager.h"
#include "Items.h"
#include "ItemManager.h"
#include "WorldPacket.h"
#include "ScriptMgr.h"
#include "WSSocket.h"
#include "Opcodes.h"
#include "Users.h"
#include "UserManager.h"
#include "MD5.h"
#include "Towns.h"
#include "OpcodesEx.h"
#include "Mails.h"
#include "MailManager.h"
#include "ChannelManager.h"
#include "Message.h"
#include "WSSocketManager.h"
#include "ResourceEventEnum.h"
#include "NoticeManager.h"
#include "GameThreadLogic.h"
#include "GatewayOpcodes.h"
#include "json/json.h"
#include "StringScreen.h"
#include "ProtocolDealEnums.h"
#include "ScriptWorldProcess.h"
#include "GameDefine.h"
#include LOG_MGR_PATH
#include LOGIC_MGR_PATH
#include PROTOCOLS_MGR_PATH
#include XMLDATA_MGR_PATH
#include "GameGoodsManager.h"
#include "GlobalCommonFunctons.h"
#include "GameDataEnum.h"
#include "subgames/Morra.h"
#include "CenterBankManager.h"
// #include "GoldCoronal.h"
#include "DataTransferManager.h"
#include "VipCardManager.h"
#include "PubDataManager.h"
#include "Tools.h"
// #include "CenterBattleManager.h"
// #include "CenterBattleLogManager.h"
// #include "CenterFriendManager.h"
#include "CenterHappyFarmManager.h"
#include "CenterClubManager.h"
#include "CRUsersManager.h"
#include "showip.h"
#include "AIInterface.h"


using namespace AIScript;
//-----------------------------------------------------------------------
bool script_world_process_pong(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr  socket = sock;

        uint16 opcode;
        uint16 len;
        uint32 serial;

        packet >> opcode;
        packet >> len;
        packet >> serial;
	
	WorldPacket newP;
	sProtocolsMgr.CreatePongPacket(&newP,serial);
	socket->SendPacket(&newP);
	
	return true;
}

//-----------------------------------------------------------------------
bool  script_world_process_timequest(ResourcePtr & sock, WorldPacket & packet)
{
	if(sock.isNull())
	{
		return true;
	}
	
	WSSocketPtr socket = sock;

	uint16 packetlen = packet.size();
	uint8 slen;
	packet.skip(2);
	packet >> slen;
	
	if(slen != packetlen || slen > 100)
	{
		Log.Debug("Packet Hacking","Client[%d] %s Error Packet len,length:%d session len:%d.", \
		socket->getHandle(),socket->GetIP(),packetlen,slen);
		socket->Disconnect();
		return true;
	}
	
	socket->TimeQuest();
	return true;	
}

//-----------------------------------------------------------------------
bool script_world_process_authentication(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	// 验证类型
	uint8 mode;
	packet >> mode;
	if(mode != GameServerTypeWorld)
	{
		Log.Debug(cCode,"Client[%d] %s Error Packet mode = %d", \
		socket->getHandle(),socket->GetIP(),mode);
		socket->Disconnect();
		return true;
	}
	// 是否第二次登录（转连接）
	uint8 bSecondLogin;
	packet >> bSecondLogin;
	
	Log.Debug("script_world_process_authentication","mode[%u] bSecondLogin[%u] packet size[%u]", mode, bSecondLogin, packet.size());
	// session字符串
	String pbuf;
	if (!GetPacketString<uint8>(&packet, pbuf))
	{
		Log.Debug(cCode,"Client[%d] %s Error Packet session len greater", \
		socket->getHandle(),socket->GetIP());
		socket->Disconnect();
		return true;
	}
	UserAuthenticInfo autheninfo;
	autheninfo.isCenter = 0;
	autheninfo.vecString = StringUtil::split(pbuf,":");	
	// StarX于2015年3月21日 下午，新增数据，用于审核时创建USER
	uint32 platform_id = 0;
	packet >> platform_id;
	autheninfo.platform_id = platform_id;
	if(autheninfo.vecString.size() < 3)
	{
		Log.Debug(cCode,"Client[%d] %s Error session authentication packet session:%s.", \
		socket->getHandle(),socket->GetIP(),pbuf.c_str());
		socket->Disconnect();
		return true;
	}
	Log.Debug("script_world_process_authentication","111User[%s] Login!  bSecondLogin[%u] platform_id[%u] pbuf[%s]", 
			autheninfo.vecString[0].c_str(), bSecondLogin, platform_id, pbuf.c_str());
	uint32 queuenum = DealAuthenticationQueueThread::g_authenQueue.size();
	if(queuenum < sXmlDataMgr.GetConfXMLValue("SYN_LAND_NUM"))
	{
		autheninfo.pSocket = (ResourcePtr)socket;
		DealAuthenticationQueueThread::g_authenQueue.add(autheninfo);
		if(sProtocolsMgr.CreateLoginQueuePacket(&packet, queuenum))
		{
			socket->SendPacket(&packet);
		}
	}
	else
	{
		if(sProtocolsMgr.CreateLoginQueuePacket(&packet, queuenum))
			socket->SendPacket(&packet);
			
		Log.Warning(cCode,"Client[%d] %s curr authenticationQueueSize[%u]", \
			socket->getHandle(),socket->GetIP(), queuenum);

		socket->Disconnect();
	}
	return true;
}


//-----------------------------------------------------------------------
bool script_world_process_request_loginserver(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
	{
		return true;
	}
		
	uint8 nCenter;
	packet >> nCenter;
	// session字符串
	String pbuf;
	if (!GetPacketString<uint8>(&packet, pbuf))
	{
		Log.Debug(cCode,"Client[%d] %s Error Packet session len greater", \
		socket->getHandle(),socket->GetIP());
		socket->Disconnect();
		return true;
	}	
	UserAuthenticInfo autheninfo;
	autheninfo.isCenter = 0;
	autheninfo.nLogic = en_UserLoginLogic_First;
	autheninfo.vecString = StringUtil::split(pbuf,":");
	// StarX于2015年3月21日 下午，新增数据，用于审核时创建USER
	uint32 platform_id = 0;
	packet >> platform_id;
	autheninfo.platform_id = platform_id;
	
	Log.Debug("script_world_process_request_loginserver","nCenter[%u] platform_id[%u] packet size[%u] pbuf[%s]", nCenter, platform_id, packet.size(), pbuf.c_str());
	
	if(autheninfo.vecString.size() < 3)
	{
		Log.Debug(cCode,"Client[%d] %s Error session authentication packet session:%s.", \
		socket->getHandle(),socket->GetIP(),pbuf.c_str());
		socket->Disconnect();
		return true;
	}
	Log.Debug("script_world_process_request_loginserver","User[%s] Login! platform_id[%u] pbuf[%s]", autheninfo.vecString[0].c_str(), autheninfo.platform_id, pbuf.c_str());
	uint32 queuenum = DealAuthenticationQueueThread::g_authenQueue.size();
	if(queuenum < sXmlDataMgr.GetConfXMLValue("SYN_LAND_NUM"))
	{
		autheninfo.pSocket = (ResourcePtr)socket;
		DealAuthenticationQueueThread::g_authenQueue.add(autheninfo);
		if(sProtocolsMgr.CreateLoginQueuePacket(&packet, queuenum))
		{
			socket->SendPacket(&packet);
		}
	}
	else
	{
		if(sProtocolsMgr.CreateLoginQueuePacket(&packet, queuenum))
			socket->SendPacket(&packet);
			
		Log.Warning(cCode,"Client[%d] %s curr authenticationQueueSize[%u]", \
			socket->getHandle(),socket->GetIP(), queuenum);

		socket->Disconnect();
	}
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_second_authentication(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	// 验证类型
	uint8 mode;
	packet >> mode;
	if(mode != GameServerTypeWorld)
	{
		Log.Debug(cCode,"Client[%d] %s Error Packet mode = %d", \
		socket->getHandle(),socket->GetIP(),mode);
		socket->Disconnect();
		return true;
	}
	// 是否第二次登录（转连接）
	uint8 bSecondLogin;
	packet >> bSecondLogin;
	// session字符串
	String pbuf;
	if (!GetPacketString<uint8>(&packet, pbuf))
	{
		Log.Debug(cCode,"Client[%d] %s Error Packet session len greater", \
		socket->getHandle(),socket->GetIP());
		socket->Disconnect();
		return true;
	}
	UserAuthenticInfo autheninfo;
	autheninfo.nLogic = en_UserLoginLogic_Second;
	autheninfo.isCenter = 0;
	autheninfo.vecString = StringUtil::split(pbuf,":");
	// platform_id由starx于2015年03月21日 晚添加
	uint32 platform_id = 0;
	packet >> platform_id;
	autheninfo.platform_id = platform_id;
	if(autheninfo.vecString.size() < 3)
	{
		Log.Debug(cCode,"Client[%d] %s Error session authentication packet session:%s.", \
		socket->getHandle(),socket->GetIP(),pbuf.c_str());
		socket->Disconnect();
		return true;
	}
	Log.Debug("script_world_process_authentication","222User[%s] Login! bSecondLogin[%u]", autheninfo.vecString[0].c_str(), bSecondLogin);
	uint32 queuenum = DealAuthenticationQueueThread::g_authenQueue.size();
	if(queuenum < sXmlDataMgr.GetConfXMLValue("SYN_LAND_NUM"))
	{
		autheninfo.pSocket = (ResourcePtr)socket;
		DealAuthenticationQueueThread::g_authenQueue.add(autheninfo);
		if(sProtocolsMgr.CreateLoginQueuePacket(&packet, queuenum))
			socket->SendPacket(&packet);
	}
	else
	{
		if(sProtocolsMgr.CreateLoginQueuePacket(&packet, queuenum))
			socket->SendPacket(&packet);			
		Log.Warning(cCode,"Client[%d] %s curr authenticationQueueSize[%u]", \
			socket->getHandle(),socket->GetIP(), queuenum);
		socket->Disconnect();
	}
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_request_changeserver(ResourcePtr & sock, WorldPacket &packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	uint16 active = 0;
	packet >> active;
	if (pChr->getStatus() != CharacterStatusFree)
	{
		if (sProtocolsMgr.CreateChangeLinkServerPacket(&packet, active, 0))
			socket->SendPacket(&packet);
	}
	else
	{
		UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
		if (pUser.isNull())
			return true;
		GameServer gs;
		sChannelMgr.getGameServer(sChannelMgr.getServerID(), gs);
		if (gs.flag & GameServerFlagMaster)
		{
			if (sProtocolsMgr.CreateChangeLinkServerPacket(&packet, active, 0))
				socket->SendPacket(&packet);
			return true;
		}
		std::list<GameServer> slist;		
		sChannelMgr.getAllServers(&slist);
		std::list<GameServer>::iterator iter, enditer = slist.end();
		for (iter = slist.begin(); iter != enditer; ++ iter)
		{
			if ((*iter).flag & GameServerFlagMaster)
			{// 主服务器
				pUser->setUInt32Field("active_gz_id", (*iter).server_id);
				pUser->SaveDB();
				break;
			}
		}
		ResourceEvent event;
		// 保存当前数据
		event.event_id = ResourceEvent_SaveDB;
		pChr->SendEvent(&event);
		// 设置为冻结
		event.event_id = ResourceEvent_Freeze;
		pChr->SendEvent(&event);
		if (sProtocolsMgr.CreateChangeLinkServerPacket(&packet, active, 1))
			socket->SendPacket(&packet);	
		
	}
	Log.Debug("script_world_process_request_changeserver","pChr[%u] active[%u]", pChr->getHandle(), active);
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_clientloadfinish(ResourcePtr & sock,WorldPacket & packet)
{		
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if (pUser.isNull())
		return true;
	
	sGLMgr.DisposeAuthentication(pChr);
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_gethallandroompersons(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint32 data1 = 0;
	packet >> data1;	
	
	// 获取房间列表
	if (sProtocolsMgr.CreateGetHallAndRoomNumberPacket(&packet, data1))
		socket->SendPacket(&packet);
		
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_getgoodslist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode, 8))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	uint8 shopType;
	packet >> shopType;
	uint8 labelType;
	packet >> labelType;
	uint8 page;
	packet >> page;
	uint8 num;
	packet >> num;
	if (num == 0)
		return true;
	UserPtr pUser = socket->getCurrentUser();
	if (pUser.isNull())
		return true;
	std::list<GameGoods*> lstGoods;
	uint8 allPage = sGoodsMgr.GetGoodsList(&lstGoods, shopType, pUser->getUInt32Field("reg_from"), labelType, page, num);
	if (allPage == 0 || allPage < page)
		return true;
	if (sProtocolsMgr.CreateGetShopGoodsPacket(&packet, shopType, labelType, allPage, page, lstGoods))
		socket->SendPacket(&packet);
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_buygoods(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	uint32 goodsId;
	packet >> goodsId;
	uint32 num;
	packet >> num;
	if (0 == num)
		return true;
	String data;
	GetPacketString<uint8>(&packet, data);
	const GameGoods *pGoods = sGoodsMgr.GetGameGoodsById(goodsId);
	if (NULL == pGoods)
		return true;
	// 计算所需金钱
	uint32 cost = num * pGoods->price;
	// 是否发生网关（兑换实物）
	bool bToGateway = pGoods->type == en_AT_RealObject;
	char billId[256];
	memset(billId, 0, sizeof(billId));
	// 检查自己的钱是否够
	uint32 myMoney;
	if ((pGoods->flag & GoodsFlag_Lottery) == GoodsFlag_Lottery)
	{// 用兑换券来兑换
		UserPtr pUser = socket->getCurrentUser();
		if (pUser.isNull())
			return true;
		myMoney = sGLMgr.GetItemNum(pChr, ItemModel_Lottery);
		// 是否要发送到网关
		if (bToGateway)
		{
			AICreatureBaseInterface* pAiChrInfe = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
			if (NULL == pAiChrInfe)
				return true;
			
			std::vector<String> vecStr = StringUtil::split(data,";");
			if (vecStr.size() != 2)
				return true;
			
			uint32 saveMoney = myMoney;
			if (myMoney < cost || !sGLMgr.reduceItemNum(pChr, ItemModel_Lottery, cost))
			{
				if (sProtocolsMgr.CreateBuyGoodsPacket(&packet, goodsId, en_BGR_BeHardUp))
					socket->SendPacket(&packet);
				return true;
			}
			// 电话号码
			String &telephone = vecStr[1];
			if (telephone.length() != 11)
				return true;
			for (uint32 i = 0; i < telephone.length(); ++i)
			{
				if (telephone[i] < '0' || telephone[i] > '9')
					return true;
			}
			char buff[256] = "";
			for (uint32 i = 0; i < num; ++i)
			{
				// 生成网关对象
				GatewayCommand gCommand;
				gCommand.uid = pUser->getHandle();
				gCommand.command_type = GameCommand_ChangePracticality;
				gCommand.group_id = sChannelMgr.getGroupID();
				gCommand.server_id = sChannelMgr.getServerID();
				gCommand.agentid = pUser->getUInt32Field("reg_from");
				gCommand.addtime = time(0);
				gCommand.cmd_status = 1;
				gCommand.gz_id = pUser->getUInt32Field("gz_id");
				gCommand.pid = pUser->getUInt32Field("platform_id");
				// 获取兑换券名称
				ItemModelPtr itemMPtr = sItemModelMgr.load(ItemModel_Lottery);
				if (itemMPtr.isNull())
					return true;
				// 生成订单号
				sprintf(billId, "%d-%d%d%d", gCommand.uid, sGLMgr.GetCurDate(), sGLMgr.GetCurTimer(), now()+i);
				Json::Value root; 
				root["oid"] = Json::Value(billId);
				root["destmodelid"] = Json::Value(pGoods->goods_id);
				root["destnum"] = Json::Value(1);
				root["srcmodelid"] = Json::Value(ItemModel_Lottery);
				root["srcnum"] = Json::Value(cost);
				root["dest_pre_num"] = Json::Value(pGoods->num);
				root["src_pre_num"] = Json::Value(saveMoney);
				root["srcitemname"] = Json::Value(itemMPtr->getStringField("name"));
				root["destitemname"] = Json::Value(pGoods->name);
				root["srcrmb"] = Json::Value(cost/10000);
				root["destrmb"] = Json::Value(0);
				root["telephone"] = Json::Value(telephone);
				Json::FastWriter fWriter; 
				gCommand.result = fWriter.write(root);
				if (!GatewayDatabase.WaitExecute("insert into gw_command(`uid`, `command_type`, `group_id`, `server_id`, `gz_id`, `pid`, `agentid`, `addtime`, `cmd_status`, \
					`result`) values(%d, %d, %d, %d, %d, %d, %d, %d, %d, '%s')", \
					gCommand.uid, gCommand.command_type, gCommand.group_id, gCommand.server_id, gCommand.gz_id, gCommand.pid, gCommand.agentid, gCommand.addtime, gCommand.cmd_status, gCommand.result.c_str()))
				{
					// 将扣除的兑换券还回去
					sGLMgr.addItemNum(pChr, ItemModel_Lottery, cost);
					// 失败
					if (sProtocolsMgr.CreateBuyGoodsPacket(&packet, goodsId, en_BGR_Unknown))
						socket->SendPacket(&packet);
					return true;
				}
				// 兑换实物日志
				sLogDataMgr.ChangePracticalityLog(pUser->getHandle(), goodsId, pGoods->name, num, cost, billId);
				// 系统消息告诉玩家
				
				memset(buff, 0, sizeof(buff));
				sprintf(buff, sMsg.getMessage("excsucceed").c_str(), pGoods->name.c_str(), billId);
				if (sProtocolsMgr.CreateLocalMessagePacket(&packet, buff, sMsg.getType("excsucceed")))
					socket->SendPacket(&packet);
				
				UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
				if(!pUser.isNull())
				{
					sGLMgr.CreateChangeMail(pUser, pGoods->name.c_str(), billId);
				}
			}
			// 公告
			memset(buff, 0, sizeof(buff));
			sprintf(buff, sMsg.getMessage("excsucceed_notice").c_str(), pChr->getStringField("name").c_str(), num, pGoods->name.c_str());
			sNoticeMgr.AddMsgToQueue(buff, sMsg.getType("excsucceed_notice"), pChr->getUInt32Field("gz_id"));
		}
		else
		{
			if (myMoney < cost || !sGLMgr.reduceItemNum(pChr, ItemModel_Lottery, cost))
			{
				if (sProtocolsMgr.CreateBuyGoodsPacket(&packet, goodsId, en_BGR_BeHardUp))
					socket->SendPacket(&packet);
				return true;
			}
		}
		// 记录商城消耗兑换券的记录
		sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Trade, ItemModel_Lottery, en_UNT_Reduce, cost, en_ShopT_LotteryShop);
		uint32 realNum = (pGoods->num == 0 ? 1 : pGoods->num) * num;
		uint32 modelId = pGoods->model_id;
		// 真实添加的物品数量
		sGLMgr.addItemNum(pChr, modelId, realNum);		
		// 记录商城购买物品的记录
		sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Trade, modelId, en_UNT_Add, realNum, (pGoods->flag & GoodsFlag_Gold) == 0 ? en_ShopT_LotteryShop : en_ShopT_GoldShop);
		
		if(pGoods->script_id != 0)
		{// 添加附加物品
			uint32 appnum = (pGoods->effect_id == 0 ? 0 : pGoods->effect_id) * num;			
			sGLMgr.addItemNum(pChr, pGoods->script_id, appnum);
			sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Trade, pGoods->script_id, en_UNT_Add, appnum, en_ShopT_Largess);
		}
	}
	else if ((pGoods->flag & GoodsFlag_Gold) == GoodsFlag_Gold)
	{// 使用元宝购买
		sGoodsMgr.BuyGoods(pChr->getHandle(), goodsId, num);
	}
	else
	{
		return true;
	}
	// 成功
	if (sProtocolsMgr.CreateBuyGoodsPacket(&packet, goodsId, en_BGR_Successed, billId))
		socket->SendPacket(&packet);
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_savesystemsetpack(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if (pUser.isNull())
		return true;
	
	String strSystemSet;
	GetPacketString<uint8>(&packet, strSystemSet);
	
	pUser->setStringField("config", strSystemSet);
	pUser->SaveDB();
	
	// 下发系统设置
	// if (sProtocolsMgr.CreateSystemSetPacket(&packet, pUser))
		// socket->SendPacket(&packet);
	return true;
}

// 保存公共设置
bool SERVER_DECL script_world_process_savecommonsetpack(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if (pUser.isNull())
		return true;
	
	String strSystemSet;
	GetPacketString<uint8>(&packet, strSystemSet);
	
	sBankMgr.SetPublicConfig(pUser, strSystemSet);
	// 下发系统设置
	// if (sProtocolsMgr.CreateSystemSetPacket(&packet, pUser))
		// socket->SendPacket(&packet);
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_geteffects(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode, 14))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint8 effType;
	uint32 modelid;
	ResourceProxy srcProxy;
	packet >> effType >> modelid >> srcProxy._type >> srcProxy._handle;
	CharPtr srcChr = sCharMgr.getByHandle(srcProxy._handle);
	if(srcChr.isNull())
		return true;
	
	if(sProtocolsMgr.CreateGetEffectsPacket(&packet, srcChr, effType, modelid))
		socket->SendPacket(&packet);
		
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_getmailslist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode, 8))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	// using AIScript::AIWorldCreatureInterface;
	AICreatureBaseInterface* pAiChrInfe = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if (NULL == pAiChrInfe)
		return true;
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if (pUser.isNull())
		return true;
	// 都不检测密码
	/* if (!pAiChrInfe->GetValidated() && pUser->getUInt32Field("status") == UserStatus_Online)
		return true; */
	
	// 检测过期邮件
	sGLMgr.CheckExpireMails(pUser->getUInt32Field("platform_id"),pChr->getUInt32Field("gz_id"));
	
	// 邮件状态及数量
	uint8 status, num; 
	// 请求邮件偏移量
	uint16 offset;
	packet >> status >> offset >> num;
	if (sProtocolsMgr.CreateGetMailsListPacket(&packet, pChr, status, offset, num))
		socket->SendPacket(&packet);
	return true;
}
//-----------------------------------------------------------------------
bool script_world_process_operatormail(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode, 9))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	// using AIScript::AIWorldCreatureInterface;
	AICreatureBaseInterface* pAiChrInfe = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if (NULL == pAiChrInfe)
		return true;
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if (pUser.isNull())
		return true;
	// 无需检测
	/* if (!pAiChrInfe->GetValidated() && pUser->getUInt32Field("status") == UserStatus_Online)
		return true; */
	// 邮件id
	uint32 mailId;
	packet >> mailId;
	// 操作类型
	uint8 operatorType;
	packet >> operatorType;
	uint8 result;
	switch (operatorType)
	{
		case en_OperatorMail_Read: // 读邮件
			{
				// 找到邮件
				GameMail pMail;
				sChannelMgr.getMailDB(mailId, &pMail);
				if (pMail.mail_id == 0)
				{
					result = en_OperatorMailResult_NoMail;
					break;
				}
				// 更改为已读状态
				if (pMail.status == Mail::MailStatusRecv)
				{
					if(pMail.send_type != en_MailSendType_AllServer)
					{// 非全服邮件类型，更新邮件状态
						pMail.status = Mail::MailStatusOpen;
						sChannelMgr.updateMailDB(&pMail);
					}
				}
				if (sProtocolsMgr.CreateSendMailContentPacket(&packet, pMail))
					socket->SendPacket(&packet);
				result = en_OperatorMailResult_Successed;
				break;
			}
		case en_OperatorMail_GetItems:	//领取附件
			{
				// 找到邮件
				GameMail pMail;
				sChannelMgr.getMailDB(mailId, &pMail);
				
				if(pMail.send_type == en_MailSendType_AllServer)	//全服邮件
				{
					result = sGLMgr.GetAllServerMailItems(pChr,mailId);
				}
				else		// 一般邮件
					result = sGLMgr.GetMailItems(pChr,mailId);
			}
			break;
		case en_OperatorMail_GetAllMailItems:	//全部领取
			{
				result = sGLMgr.GetAllMailsItems(pChr);
			}
			break;
		case en_OperatorMail_ReadAllMails:		// 全部已读
			{
				result = sGLMgr.ReadAllMails(pChr);
			}
			break;
		case en_OperatorMail_Delete:			// 删除邮件
			{
				result = sGLMgr.DeleteMail(pChr, mailId);
			}
			break;
		case en_OperatorMail_DeleteAll:			// 一件删除
			{
				return true;
			}
			break;
		default:
			return true;
	}
	
	if (sProtocolsMgr.CreateOperatorMailResultPacket(&packet, mailId, operatorType, result))
		socket->SendPacket(&packet);
	
	if(result == en_OperatorMailResult_Successed)
	{
		if (sProtocolsMgr.CreateSendUnreadMailNumberPacket(&packet, pUser))
			socket->SendPacket(&packet);
		if(operatorType == en_OperatorMail_GetAllMailItems || operatorType == en_OperatorMail_GetItems)
		{
			if(sProtocolsMgr.CreateGetMailsListPacket(&packet,pChr,en_MailListStatus_All,0,sXmlDataMgr.GetConfXMLValue("MAIL_LIMITNUM")))
				socket->SendPacket(&packet);
		}
	}
	
	// 检测过期邮件
	sGLMgr.CheckExpireMails(pUser->getUInt32Field("platform_id"),pChr->getUInt32Field("gz_id"));
	return true;
}
//-----------------------------------------------------------------------
bool script_world_process_changesecondpwd(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	String oldPwd, newPwd;
	GetPacketString<uint8>(&packet, oldPwd);
	GetPacketString<uint8>(&packet, newPwd);

	AICreatureBaseInterface* pAiChrInfe = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if (NULL == pAiChrInfe)
		return true;
	UserPtr pUser = socket->getCurrentUser();
	if (pUser.isNull())
		return true;
	Operator2PwdResult opr = (Operator2PwdResult)pAiChrInfe->ValidateSecondPassword(oldPwd);
	if (sProtocolsMgr.CreateChangeSecondPwdPacket(&packet, opr))
		socket->SendPacket(&packet);
	if(opr == en_Operator2PwdResult_Success)
	{
		String tempPwd = ServerDatabase.EscapeString(newPwd);
		pUser->setStringField("passwd2", tempPwd);		
		pUser->SaveDB();
		
		sBankMgr.SetPassworld(pUser, tempPwd);		
	}
	
	return true;
}
//-----------------------------------------------------------------------
bool script_world_process_validatesecondpwd(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	String pwd;
	GetPacketString<uint8>(&packet, pwd);
	// using AIScript::AIWorldCreatureInterface;
	AICreatureBaseInterface* pAiChrInfe = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if (NULL == pAiChrInfe)
		return true;
	if (sProtocolsMgr.CreateValidateSecondPwdPacket(&packet, pAiChrInfe->ValidateSecondPassword(pwd)))
		socket->SendPacket(&packet);
	return true;
}
//-----------------------------------------------------------------------
bool script_world_process_exchangeticket(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	// using AIScript::AIWorldCreatureInterface;
	AICreatureBaseInterface* pAiChrInfe = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if (NULL == pAiChrInfe)
		return true;
	String ticket;
	GetPacketString<uint8>(&packet, ticket);
	// 检测卡号长度
	if (ticket.length() != 21)
		return true;
	String name = ticket.substr(0,2);
	uint8 status;
	if (pAiChrInfe->GetXMLData(name) == 1)
		status = en_ExchangeResult_PlayerExchanged;
	else
	{
		status = sGLMgr.CkExchageTicket(pChr, ticket);
		if (en_ExchangeResult_Success == status)
		{
			pAiChrInfe->SetXMLData(name, 1);
			pChr->SaveDB();
		}
	}
	if (sProtocolsMgr.CreateExchageTicketPacket(&packet, status))
		socket->SendPacket(&packet);
	return true;
}

// SMSG_EXCHANGEGATEWAYGOODS = 0x005B,	兑换网关配置道具 
bool SERVER_DECL script_world_process_exchangegatewaygoods(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint32 prizes_id;
	uint32 num;
	
	packet >> prizes_id >> num;
	Log.Debug("script_world_process_exchangegatewaygoods","char[%u] prizes_id[%u] num[%u]", pChr->getHandle(), prizes_id, num);
	
	Json::Value val;
	val["id"] = prizes_id;
	val["num"] = num;
	
	Json::FastWriter w;
	String strData = w.write(val);
	sGLMgr.ExchangeRealGoods(pChr, strData);
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_rename(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	UserPtr pSockUser = socket->getCurrentUser();
	if (pSockUser.isNull())
		return true;
	
	String newNick;
	GetPacketString<uint8>(&packet, newNick);	
	// 转UTF8
	// newNick = StringUtil::StringToUTF8(newNick);
	// trim
	StringUtil::trim(newNick);
	
	char buf[256] = "";
	sprintf(buf, "CLOSE_CHANGE_NICKNAME_%u", pSockUser->getUInt32Field("reg_from"));
	
	if(sXmlDataMgr.GetConfXMLValue(buf) == 0)
	{// 没有配置关闭修改昵称的
		int loc = newNick.find("贵宾", 0);
		if (loc != -1)
		{
			newNick = pChr->getStringField("name");
			loc = newNick.find("贵宾", 0);
			if (loc != -1)
				newNick = sGLMgr.GetNickWords();
		}
	}
	
	String url;
	GetPacketString<uint8>(&packet, url);
	
	// 转UTF8
	// url = StringUtil::StringToUTF8(url);
	// trim
	StringUtil::trim(url);
	uint8 sex;
	packet >> sex;
	
	Log.Debug("script_world_process_rename","char[%u] sex[%u] newNick[%s] url[%s]",pChr->getHandle(),sex,newNick.c_str(),url.c_str());
	
	pChr->setUInt32Field("sex", sex);
	pChr->setStringField("name", newNick);
	pChr->setStringField("desc", url);
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if(!pUser.isNull())
	{
		pUser->setStringField("nick", newNick);
		pUser->setStringField("banner", url);
		pUser->SaveDB();
		
		if(pUser->getUInt32Field("reg_from") == 5045 || pUser->getUInt32Field("reg_from") == 5046)
		{// 俱乐部用户更新昵称相关信息
			uint32 pid = pUser->getUInt32Field("platform_id");
			
			// 俱乐部会长名字更新
			Fields fieldsGameClub;
			fieldsGameClub["owner_nick"] = newNick;
			sCenterClubMgr.UpdateCenterClub(&fieldsGameClub, "status < 255 and owner_pid = %u", pid);
			
			// 俱乐部日志消息
			Fields fieldsGameClubLogs;
			fieldsGameClubLogs["nick"] = newNick;
			sCenterClubLogMgr.UpdateCenterClubLog(&fieldsGameClubLogs, "status < 255 and pid = %u", pid);
			
			// 俱乐部成员
			Fields fieldsGameClubMember;
			fieldsGameClubMember["nick"] = newNick;
			sCenterClubMemberMgr.UpdateCenterClubMember(&fieldsGameClubMember, "status < 255 and pid = %u", pid);
			
			// 俱乐部消息
			Fields fieldsGameClubMessage;
			fieldsGameClubMessage["owner_nick"] = newNick;
			sCenterClubMessageMgr.UpdateCenterClubMessage(&fieldsGameClubMessage, "status < 255 and owner_pid = %u", pid);
			
			// 俱乐部备注
			Fields fieldsGameClubRemark;
			fieldsGameClubRemark["dest_nick"] = newNick;
			sCenterClubRemarkMgr.UpdateCenterClubRemark(&fieldsGameClubRemark, "status < 255 and src_pid = %u", pid);
		}
	}
	
	
	
	return true;
}
// 聊天协议
bool script_world_process_chat(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
		
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
		
	uint8 type;
	uint32 serial;
	uint32 color;
	String szContent;
	packet >> type >> serial >> color;
	GetPacketString<uint16>(&packet, szContent);
	if(type != 4)
	{// 过滤信息内容
		sStrConverMgr.StringConverter_Ext(szContent);
	}
	
	// 禁言后消息返给发言者
	if (IS_CREATURE_FLAG(pChr, en_CreatureFlag_Shutup))
	{
		CharPtr target;
		if(sProtocolsMgr.CreateChatMessagePacket(&packet, type, pChr, szContent, target, color))
			socket->SendPacket(&packet);
		return true;
	}
	
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if(pUser.isNull())
		return true;
	
	uint32 fromid = pUser->getUInt32Field("reg_from");
	if(type == en_ChatType_All)
	{// 全服公聊
		// 加开关屏蔽原来协议 然后LOG下来
		if(sXmlDataMgr.GetConfXMLValue("ORG_LABA0074_CLOSE"))
		{
			Log.Debug("script_world_process_chat","char[%u] pid[%u] use old chat procotol!",pChr->getHandle(),pUser->getUInt32Field("platform_id"));
			return true;
		}
		
		CharPtr target;
		if(!sProtocolsMgr.CreateChatMessagePacket(&packet, type, pChr, szContent, target, color))
			return true;

		if(!sGLMgr.reduceItemNum(pChr, ItemModel_Bugle, 1))
		{
			sGLMgr.SendSystemMessage(pChr, sMsg.getMessage("send_lose").c_str(), sMsg.getType("send_lose"));
			return true;
		}
		
		sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Chat, ItemModel_Bugle, en_UNT_Reduce, 1, 0);		
		sGLMgr.BroadcastByFromID(&packet, fromid, pChr->getUInt32Field("flag"));
	}
	else if(type == en_ChatType_Table)
	{// 牌桌聊天
		uint32 lv = sXmlDataMgr.GetConfXMLValue("CHAT_SERVER_LV");
		if (pChr->getUInt32Field("lv") < lv)
		{
			// 下发权限不足
			char msg[256] = "";
			sprintf(msg, sMsg.getMessage("server_bugle").c_str(), lv);
			sGLMgr.SendSystemMessage(pChr, msg, sMsg.getType("server_bugle"));
			return true;
		}
		
		AICreatureBaseInterface* pAiChrInfe = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
		if (pAiChrInfe == NULL)
			return true;
		
		ChannelPtr pChannel = pAiChrInfe->GetChannelPtr();
		if (pChannel.isNull())
			return true;
		
		AIChannelBaseInterface *pAiChanInfe = TO_CHANNEL_BASE_INTERFACE(pChannel->getAIInterface());
		if (pAiChanInfe == NULL)
			return true;
			
		CharPtr target;
		if(sProtocolsMgr.CreateChatMessagePacket(&packet, type, pChr, szContent, target, color))
			pAiChanInfe->BroadcastPacket(&packet);
	}
	else if(type == en_ChatType_Private)
	{// 私聊
		CharPtr target = sCharMgr.getByHandle(serial);
		if(target.isNull())
			return true;
		
		if(pChr->getUInt32Field("gz_id") != target->getUInt32Field("gz_id"))
			return true;
		
		if(!sProtocolsMgr.CreateChatMessagePacket(&packet, type, pChr, szContent, target, color))
			return true;
		
		if(target.isNull())
		{
			sGLMgr.SendSystemMessage(pChr, sMsg.getMessage("target_error").c_str(), sMsg.getType("target_error"));
			return true;
		}
		
		WSSocketPtr pSocket = target->getSocket();
		if(pSocket.isNull())
		{
			sGLMgr.SendSystemMessage(pChr, sMsg.getMessage("target_error").c_str(), sMsg.getType("target_error"));
			return true;
		}
		
		pSocket->SendPacket(&packet);
		socket->SendPacket(&packet);
	}
	else if(type == en_ChatType_QiPao)
	{
		AICreatureBaseInterface* pAiChrInfe = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
		if (pAiChrInfe == NULL)
			return true;
		
		ChannelPtr pChannel = pAiChrInfe->GetChannelPtr();
		if (pChannel.isNull())
			return true;
		
		AIChannelBaseInterface *pAiChanInfe = TO_CHANNEL_BASE_INTERFACE(pChannel->getAIInterface());
		if (pAiChanInfe == NULL)
			return true;
		
		CharPtr target;
		if(sProtocolsMgr.CreateChatMessagePacket(&packet, type, pChr, szContent, target, color))
			pAiChanInfe->BroadcastPacket(&packet);
	}
	
	return true;
} 

// 新喇叭聊天协议
bool SERVER_DECL script_world_process_single_labachat(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	String szContent;
	GetPacketString<uint16>(&packet, szContent);
	sStrConverMgr.StringConverter_Ext(szContent);	// 过滤信息内容
	
	// 禁言后消息返给发言者
	if (IS_CREATURE_FLAG(pChr, en_CreatureFlag_Shutup))
	{
		if(sProtocolsMgr.CreateSingleLabaChatPacket(&packet,pChr,szContent))
			socket->SendPacket(&packet);
		return true;
	}
	
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if(pUser.isNull())
		return true;
	
	uint32 agent_id = pUser->getUInt32Field("reg_from");
	
	uint32 need_modelid = sXmlDataMgr.GetConfXMLValue("LABA_NEED_ITEMMODELID_AGENT_0");
	uint32 need_num = sXmlDataMgr.GetConfXMLValue("LABA_NEED_ITEMNUM_AGENT_0");
	
	char buf_model[256] = "";
	char buf_num[256] = "";
	sprintf(buf_model,"LABA_NEED_ITEMMODELID_AGENT_%u", agent_id);
	sprintf(buf_num,"LABA_NEED_ITEMNUM_AGENT_%u", agent_id);
	if(sXmlDataMgr.GetConfXMLValue(buf_model) && sXmlDataMgr.GetConfXMLValue(buf_num))
	{
		need_modelid = sXmlDataMgr.GetConfXMLValue(buf_model);
		need_num = sXmlDataMgr.GetConfXMLValue(buf_num);
	}
	
	if(need_modelid && need_num)
	{
		if(!sGLMgr.reduceItemNum(pChr, need_modelid, need_num))
		{// 喇叭数量是否充足
			sGLMgr.SendSystemMessage(pChr, sMsg.getMessage("send_lose").c_str(), sMsg.getType("send_lose"));
			return true;
		}
		
		CharPtr target;
		if(!sProtocolsMgr.CreateSingleLabaChatPacket(&packet,pChr,szContent))
			return true;
		
		sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Chat, need_modelid, en_UNT_Reduce, need_num, 0);		
		sGLMgr.BroadcastByFromID(&packet, agent_id, pChr->getUInt32Field("flag"));
	}
	
	return true;
}

// 发送弹幕
//-----------------------------------------------------------------------
bool SERVER_DECL script_world_process_senddanmu(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
		
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint8 type;
	uint16 pos;
	uint32 danmu_serial;
	String content;
	packet >> type >> pos >> danmu_serial;
	// 读取内容
	GetPacketString<uint8>(&packet, content);
	// 过滤敏感字符
	sStrConverMgr.StringConverter_Ext(content);
	
	switch(type)
	{
	case enDanMuType_Channel:
		{
			sGLMgr.SendChannelDanMu(pChr,danmu_serial,pos,content);
			break;
		}
	case enDanMuType_Town:
		{
			sGLMgr.SendTownDanMu(pChr,danmu_serial,pos,content);
			break;
		}
	default:
		break;
	}
	
	return true;
}

// 弹幕历史
//-----------------------------------------------------------------------
bool SERVER_DECL script_world_process_danmuhistory(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
		
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint8 type;
	packet >> type;
	
	Log.Debug("script_world_process_danmuhistory","char[%u] want danmu history type[%u]!",pChr->getHandle(),type);
	sGLMgr.GetDanMuHistoryList(pChr,type);
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_getbankcoins(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	UserPtr pUser = socket->getCurrentUser();
	if (pUser.isNull())
		return true;
	// 下发银行信息
	// CenterBankManager *pBankMgr = new CenterBankManager();
	GameBank bank;
	if (sBankMgr.GetRealBank(pUser, bank))
	{
		if (sProtocolsMgr.CreateGetBankInfoPacket(&packet, bank))
			socket->SendPacket(&packet);
	}
	// delete pBankMgr;
	return true;
}
//-----------------------------------------------------------------------
bool script_world_process_putcoinsinbank(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	UserPtr pUser = socket->getCurrentUser();
	if (pChr.isNull() || pUser.isNull())
		return true;
	uint8 type;
	uint32 saveWealth; // 要存的钱
	packet >> type >> saveWealth;
	if (saveWealth < sXmlDataMgr.GetConfXMLValue("BANK_MINSAVE"))
		return true;
	uint32 modelId = 0;
	uint32 myWealth = 0;
	uint32 gzid = pUser->getUInt32Field("gz_id");
	if(gzid == 0)
		return true;
	
	switch(type)
	{
		case 1:// 铜钱
		{
			modelId = en_ItemModelId_Coins;
			const String *field = sBankMgr.GetFieldName(gzid, modelId);
			if(field == NULL || *field == "")
				return true;
			
			myWealth = pChr->getUInt32Field(*field);
			break;
		}
		// case 2:// 代币
		// {
			// modelId = en_ItemModelId_Gold;
			// myWealth = pChr->getUInt32Field("coins");
			// break;
		// }
		// case 3:// 参赛券
		// {
			// modelId = en_ItemModelId_Match;
			// myWealth = pChr->getUInt32Field("speed_org");
			// break;
		// }
		// case 4:// 兑换券
		// {
			// modelId = en_ItemModelId_Exchange;
			// myWealth = pChr->getUInt32Field("speed2");
			// break;
		// }				
		default:
			return true;
	}
	
	uint32 result = en_BankCoins_Faild;
	if (myWealth < saveWealth)
		result = en_BankCoins_Scanty;
	else
	{
		// CenterBankManager *pBankMgr = new CenterBankManager();
		if (sGLMgr.reduceItemNum(pChr, modelId, saveWealth))
		{
			if (sBankMgr.SaveWealthInBank(pUser, modelId, saveWealth))
			{
				result = en_BankCoins_Ok;
			}
			else
			{
				sGLMgr.addItemNum(pChr, modelId, saveWealth);
			}
		}
		// delete pBankMgr;
	}
	if(sProtocolsMgr.CreatePutCoinsInBankPacket(&packet, result, type, saveWealth))
		socket->SendPacket(&packet);
	if (en_BankCoins_Ok == result)
	{
		// 消息
		char msg[256];
		sprintf(msg, (sMsg.getMessage("save_bank")+sMsg.getMessage("item_num")).c_str(), saveWealth, sGLMgr.GetItemName(modelId).c_str());
		sGLMgr.SendSystemMessage(pChr, msg, sMsg.getType("save_bank"));
		// 本地存款日志		
		sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Bank, modelId, en_UNT_Reduce, saveWealth);
		
	}
	
	return true;
}
//-----------------------------------------------------------------------
bool script_world_process_getcoinsfrombank(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	UserPtr pUser = socket->getCurrentUser();
	if (pChr.isNull() || pUser.isNull())
		return true;
	uint32 gzid = pUser->getUInt32Field("gz_id");
	if(gzid == 0)
		return true;
	
	using namespace AIScript;
	AICreatureBaseInterface* pAiChrInfe = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if (pAiChrInfe)
	{		
		uint8 type;
		uint32 getWealth; // 要取的钱
		packet >> type >> getWealth;
		if (getWealth < sXmlDataMgr.GetConfXMLValue("BANK_MINGET"))
			return true;
		String pwd; // 密码
		GetPacketString<uint8>(&packet, pwd);
		uint32 result = pAiChrInfe->ValidateSecondPassword(pwd);
		uint32 modelId =0;
		uint32 status = pUser->getUInt32Field("status");
		if (status != UserStatus_Online)// 非电脑登录,判断密码
			result = en_Operator2PwdResult_Success;
		if (en_Operator2PwdResult_Success == result)
		{
			uint32 myWealth = 0;
			const String *field = NULL;
			switch(type)
			{
				case 1:// 铜钱
				{
					modelId = en_ItemModelId_Coins;
					field = sBankMgr.GetFieldName(gzid,modelId);
					// myWealth = pChr->getUInt32Field(sBankMgr.GetFieldName(gzid,modelId));
					break;
				}
				case 2:// 代币
				{
					modelId = en_ItemModelId_Gold;
					field = sBankMgr.GetFieldName(gzid,modelId);
					// myWealth = pChr->getUInt32Field(sBankMgr.GetFieldName(gzid,modelId));
					break;
				}
				case 3:// 参赛券
				{
					modelId = en_ItemModelId_Match;
					field = sBankMgr.GetFieldName(gzid,modelId);
					// myWealth = pChr->getUInt32Field(sBankMgr.GetFieldName(gzid,modelId));
					break;
				}
				case 4:// 兑换券
				{
					modelId = en_ItemModelId_Exchange;
					field = sBankMgr.GetFieldName(gzid,modelId);
					// myWealth = pChr->getUInt32Field(sBankMgr.GetFieldName(gzid,modelId));
					break;
				}				
				default:
					break;
			}
			
			if(field == NULL || *field == "")
			{
				Log.Error("script_world_process_getcoinsfrombank", "script_world_process_getcoinsfrombank pChr[%u] modelid[%u] field is null!", 
						pChr->getHandle(), modelId);
				return true;
			}
			
			myWealth = pChr->getUInt32Field(*field);
			if (myWealth + getWealth > sXmlDataMgr.GetConfXMLValue("MAX_COINS"))
				result = en_GetBankCoins_Overflow;
			else
			{
				// CenterBankManager *pBankMgr = new CenterBankManager();
				if (sBankMgr.GetWealthFromBank(pUser, modelId, getWealth))
				{
					sGLMgr.addItemNum(pChr, modelId, getWealth);
					result = en_GetBankCoins_Ok;
				}
				else
					result = en_GetBankCoins_Faild;
				// delete pBankMgr;
			}
		}
		if(sProtocolsMgr.CreateGetCoinsFromBankPacket(&packet, result, type, getWealth))
			socket->SendPacket(&packet);
		if (en_GetBankCoins_Ok == result)
		{
			// 消息
			char msg[256];
			sprintf(msg, sMsg.getMessage("get_bank").c_str(), getWealth, sGLMgr.GetItemName(modelId).c_str());
			sGLMgr.SendSystemMessage(pChr, msg, sMsg.getType("get_bank"));
			sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Bank, modelId, en_UNT_Add, getWealth);
			// 本地取款日志
			// sLogDataMgr.AboutBankLog(pChr, en_BankType_Get, modelId, getWealth, 0);
		}
	}
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_getbankhistory(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	UserPtr pUser = socket->getCurrentUser();
	if (pUser.isNull())
		return true;
	uint8 numPerPage;
	uint16 page;
	packet >> numPerPage >> page;
	// 下发银行信息
	if (sProtocolsMgr.CreateGetBankHistoryPacket(&packet, pUser->getUInt32Field("platform_id"), numPerPage, page))
		socket->SendPacket(&packet);

	return true;
}
//-----------------------------------------------------------------------
bool script_world_process_getonlinegift(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
	{
		Log.Debug("bdx_script_world_process_getonlinegift","socket[%u] Chr is null!", socket->getHandle());
		return true;
	}
	
	uint8 id;
	packet >> id;
	Log.Debug("bdx_script_world_process_getonlinegift","char[%u] get online id[%u]", pChr->getHandle(), id);
	
	AICreatureBaseInterface *pChrAIInfe = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if (NULL == pChrAIInfe)
		return true;
	
	pChrAIInfe->GetCommonOnlineGiftBounty(id);
	return true;
}
//-----------------------------------------------------------------------
bool script_world_process_operationgameserver(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	if(pChr->getStatus() != CharacterStatusFree)
	{
		return true;
	}
	
	UserPtr pUser = socket->getCurrentUser();
	if(pUser.isNull())
		return true;
	
	uint8 type;
	uint16 serverid;
	packet >> type >> serverid;	
	
	std::list<GameBank> lstBankInfo;
	if (!sChannelMgr.getBankList(&lstBankInfo, 0, 1, "`platform_id` = %u and `type` = %u", pUser->getUInt32Field("platform_id"), 1))
		return true;
	GameBank bank = lstBankInfo.front();
	Log.Debug("script_world_process_operationgameserver", "0000can leaveGameSev pUser[%u] serverid[%u] bank status[%u] packet[%u]", 
					pUser->getHandle(), serverid, bank.status, packet.size());
	
	uint32 gameid = pUser->getUInt32Field("gz_id");
	if (bank.status == 1 || bank.status == 7)
	{		
		if(sBankMgr.LeaveGameServer(pUser, gameid, serverid))
		{
			if(sBankMgr.CreateOpServerResult(&packet, type, 0, serverid))
				socket->SendPacket(&packet);
			
			// Log.Debug("script_world_process_operationgameserver", "1111can leaveGameSev pUser[%u] serverid[%u]", pUser->getHandle(), serverid);
			return true;
		}
	}
	else
	{		
		if(sBankMgr.JoinGameServer(pUser, gameid))
		{
			sGLMgr.NewPlayerSubsidy(pChr);
			if(sBankMgr.CreateOpServerResult(&packet, type, 0, serverid))
				socket->SendPacket(&packet);
			
			// Log.Debug("script_world_process_operationgameserver", "4444can JoinGameServer pUser[%u] serverid[%u] type[%u]", pUser->getHandle(), serverid, type);
			return true;
		}
	}
	
	if(sBankMgr.CreateOpServerResult(&packet, type, 1, serverid))
		socket->SendPacket(&packet);
	
	// Log.Debug("script_world_process_operationgameserver", "cann't leaveGameSev pUser[%u] type[%u] ishere[%u] serverid[%u]", pUser->getHandle(), type, pChr->getUInt32Field("ishere"), serverid);
	
	return true;
}

bool script_world_process_baseupdatebiamondlevel(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	uint32 level;
	packet >> level;
	String strLevel;
	GetPacketString<uint8>(&packet, strLevel);
	UserPtr pUser = socket->getCurrentUser();
	if (pUser.isNull())
		return true;
	// 检测字符串是否匹配
	char str[512];
	sprintf(str, "%u%u%s", pUser->getUInt32Field("platform_id"), level, SERVER_SIGN_CODE);
	CMD5 md5;
	String strCheck = md5.GenerateMD5(str);
	uint8 result = 1;
	if (strCheck == strLevel)
	{
		if (pChr->getUInt32Field("rank") != level)
		{
			pChr->setUInt32Field("rank", level);	
			pChr->SaveDB();
		}
	}
	else
		result = 2;
	
	uint8 yellowstatus = en_YellowStatus_None;
	if(result == 1 && level != 0)
	{
		// if(pUser->getUInt32Field("flag") == 0)
		// {// 是独立应用才能领取			
			AICreatureBaseInterface * pACBI = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
			if(pACBI == NULL)
				return true;
			GameBank bank;
			sBankMgr.GetPublicData(pUser, &bank);
			uint32 hzlogin = sBankMgr.GetUserDataVal(bank, "HZDLLB");
			uint32 hzxslb = sBankMgr.GetUserDataVal(bank, "HZXSLB");
			if(!hzxslb)
			{// 有黄钻,但未领取新手礼包
				yellowstatus = en_YellowStatus_NewPlayer;
			}
			else if(!hzlogin || !sGLMgr.IsSameDate(hzlogin, time(0)))
			{
				sBankMgr.SetUserDataVal(bank, "HZDLLB", 0);
				sBankMgr.SaveUserDataDB(bank);
				yellowstatus = en_YellowStatus_Login;
			}
			else 
				yellowstatus = en_YellowStatus_NoBounty;
			
		// }
	}
	
	if(sProtocolsMgr.CreateYellowStatusUpdate(&packet, yellowstatus))
		socket->SendPacket(&packet);	

	Log.Debug("script_world_process_centerupdatebiamondlevel", "pUser[%u] update diamand!", pUser->getHandle());
	return true;
}

bool script_world_process_baseoperationbiamondlevel(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint8 type = 0;
	packet >> type;
	AICreatureBaseInterface * pACBI = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if(pACBI == NULL)
		return true;
	
	uint32 rank = pChr->getUInt32Field("rank");
	if(!rank)
		return true;
	UserPtr pUser = socket->getCurrentUser();
	if (pUser.isNull())
		return true;
	
	// 子游戏不允许领取
	// if(pUser->getUInt32Field("flag") == 1)
		// return true;
	GameBank bank;
	sBankMgr.GetPublicData(pUser, &bank);
	uint32 ntime = time(0);
	uint8 re = en_YellowStatus_None;
	if(type == en_YellowStatus_NewPlayer)
	{// 领取新手礼包
		uint32 ishzxslb = sBankMgr.GetUserDataVal(bank, "HZXSLB");
		// uint8 ishzxslb = pACBI->GetXMLData("HZXSLB");
		if(!ishzxslb)
		{
			sBankMgr.SetUserDataVal(bank, "HZXSLB", ntime);
			sBankMgr.SaveUserDataDB(bank);
			// pACBI->SetXMLData("HZXSLB", ntime);
			const WebLvBounty* wl = sXmlDataMgr.GetWebLevelBounty(101);
			if(wl)
			{
				if(wl->money)
				{
					sGLMgr.addItemNum(pChr, ItemModel_Coins, wl->money);
					sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Hortation, ItemModel_Coins, en_UNT_Add, wl->money, en_HSI_HZJackeroo);
				}
				
				if(wl->match)
				{
					sGLMgr.addItemNum(pChr, ItemModel_March, wl->match);
					sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Hortation, ItemModel_March, en_UNT_Add, wl->match, en_HSI_HZJackeroo);
				}
				
				if(wl->jb)
				{
					sGLMgr.addItemNum(pChr, ItemModel_Golds, wl->jb);
					sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Hortation, ItemModel_Golds, en_UNT_Add, wl->jb, en_HSI_HZJackeroo);
				}
				
				re = en_YellowStatus_Login;
			}
			else
				re = en_YellowStatus_None;
			
		}
	}
	else if(type == en_YellowStatus_Login)
	{// 领取登陆礼包
		uint32 hzdllb = sBankMgr.GetUserDataVal(bank, "HZDLLB");
		if(!hzdllb)
		{
			// pACBI->SetXMLData("HZDLLB", ntime);
			sBankMgr.SetUserDataVal(bank, "HZDLLB", ntime);
			sBankMgr.SaveUserDataDB(bank);
			const WebLvBounty* wl = sXmlDataMgr.GetWebLevelBounty(rank%100);
			if(wl)
			{
				if(wl->match)
				{
					sGLMgr.addItemNum(pChr, ItemModel_March, wl->match);
					sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Hortation, ItemModel_March, en_UNT_Add, wl->match, en_HSI_HZLogin);
				}
				
				if(wl->money)
				{
					sGLMgr.addItemNum(pChr, ItemModel_Coins, wl->money);
					sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Hortation, ItemModel_Coins, en_UNT_Add, wl->money, en_HSI_HZLogin);
				}
			}			
			
			if(rank > 100)
			{// 年费用户
				const WebLvBounty* wl = sXmlDataMgr.GetWebLevelBounty(100);
				if(wl)
				{
					if(wl->money)
					{
						sGLMgr.addItemNum(pChr, ItemModel_Coins, wl->money);
						sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Hortation, ItemModel_Coins, en_UNT_Add, wl->money, en_HSI_HZYearUser);
					}
					
					if(wl->match)
					{
						sGLMgr.addItemNum(pChr, ItemModel_March, wl->match);
						sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Hortation, ItemModel_Coins, en_UNT_Add, wl->match, en_HSI_HZYearUser);
					}
				}
			}
			
			re = en_YellowStatus_NoBounty;
		}
	}
	
	if(sProtocolsMgr.CreateYellowStatusUpdate(&packet, re))
		socket->SendPacket(&packet);	
	
	Log.Debug("script_world_process_centeroperationbiamondlevel", "type[%u] re[%u]", type, re);
	return true;
}
//-----------------------------------------------------------------------
bool script_world_process_geteffortlist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (!pChr.isNull() && sProtocolsMgr.CreateGetEffortListPacket(&packet, pChr))
		socket->SendPacket(&packet);
	return true;
}

// 获取完整成就列表数据
bool SERVER_DECL script_world_process_servereffortlist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if(pChr.isNull())
		return true;
	
	// Log.Notice("script_world_process_servereffortlist","player[%u]",pChr->getHandle());
	std::list<EffectPtr> effects;
	pChr->getEffectsList(&effects);
	
	if (!pChr.isNull() && sProtocolsMgr.CreateServerEffortListPacket(&packet, pChr,effects))
		socket->SendPacket(&packet);
	return true;
}
// 领取成就奖励
bool SERVER_DECL script_world_process_effortbounty(ResourcePtr & sock,WorldPacket & packet)
{
	if(sock.isNull())
		return true;
	
	WSSocketPtr socket = sock;
	char cCode[256] = "";
	if(!ChkSocketPacket(socket,packet,cCode))
		return true;
	
	CharPtr pChr = socket->m_Char.getResourcePtr();
	if(pChr.isNull())
		return true;
	
	uint16 model_id;
	packet >> model_id;
	// Log.Debug("script_sssworld_process_geteffort_bounty","get model_id[%u] effort bounty!",model_id);
	
	std::list<EffectPtr> effects;
	pChr->getEffectsList(&effects);
	
	bool re = false;
	uint32 coins = 0;
	uint32 diamand = 0;
	std::list<EffectPtr>::iterator iter,ei = effects.end();
	for(iter = effects.begin(); iter!=ei; ++iter)
	{
		EffectModelPtr model = (*iter)->model;
		if(model->getHandle() != model_id)
			continue;
		
		if ((*iter)->getUInt32Field("effect_type") != en_EffectStatus_Sucess)
			return true;
		
		AICreatureBaseInterface *pChrAiInfe = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
		if(!pChrAiInfe)	
			return true;
		
		Log.Warning("TWMJGameLogicManager::CompleteEffort", "effect_model_id[%u] completed", model->getHandle());
		// 下发产生新成就
		WorldPacket packet;
		uint32 effortId = model->getHandle();
		pChrAiInfe->addTitle(effortId);
		// 成就点
		uint32 effortPoint = pChr->getUInt32Field("country_contribute") + (*iter)->model->getUInt32Field("effect3");
		// 奖励铜钱
		coins = (*iter)->model->getUInt32Field("effect2");
		pChr->setUInt32Field("country_contribute", effortPoint);
		if (coins)
		{
			sGLMgr.addItemNum(pChr, ItemModel_Coins, coins);
			sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Effect, ItemModel_Coins, en_UNT_Add, coins, effortId);
		}
		
		// 奖励钻石/房卡
		diamand = (*iter)->model->getUInt32Field("effect4");
		if (diamand)
		{
			sGLMgr.addItemNum(pChr, ItemModel_DiamondOpen, diamand);
			sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Effect, ItemModel_DiamondOpen, en_UNT_Add, diamand, effortId);
		}
		
		// 消息
		char msg[256];
		sprintf(msg, sMsg.getMessage("new_effort").c_str(), model->getStringField("name").c_str(), coins);
		sGLMgr.SendSystemMessage(pChr, msg, sMsg.getType("new_effort"));
		
		(*iter)->Destroy();
		
		re = true;
		break;
	}
	
	if(sProtocolsMgr.CreateGetEffortBountyPacket(&packet,model_id,re))
		socket->SendPacket(&packet);
	
	return true;
}

bool script_world_process_base_operatorobject(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode, 15))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	// 对象类型
	uint8 objectType;
	packet >> objectType;
	// 对象id
	uint32 objectId;
	packet >> objectId;
	// 操作类型
	uint8 operatorType;
	packet >> operatorType;
	// 目标
	ResourceProxy target;
	packet >> target._type;
	packet >> target._handle;

	return true;
}

bool script_world_process_baseeffortsign(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	uint32 serial,time_now;
	uint8 type;
	packet >> type >> serial >> time_now;
	
	char str[1024];
	sprintf(str, "%u%u%s", serial,time_now+15,SERVER_SIGN_CODE);
	CMD5 md5;
	String strCheck = md5.GenerateMD5(str);
	
	Log.Debug("script_world_process_baseeffortsign", "serial[%u] time_now+15[%u] str[%s] strCheck[%s]", serial, time_now+15, str, strCheck.c_str());
	if(sProtocolsMgr.CreateEffortSignPacket(&packet,type,serial,time_now,strCheck))
		socket->SendPacket(&packet);
	
	return true;
}

bool script_world_process_basegaingift(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
		
	uint8 type;
	uint32 data1;
	packet >> type >> data1;
	if (type == en_NGB_Welfare)
	{// 领取福利卡
		sGLMgr.GainWelfare(pChr);
		return true;
	}
	else if (type == en_NGB_Subsidy)
	{// 领取救济卡
		sGLMgr.GainSubsidyCard(pChr);
		return true;
	}
	else if (type == en_NGB_SysSubsidy)
	{
		sGLMgr.NewPlayerSubsidy(pChr, true);
		return true;
	}
	else if(type == en_NGB_WelfareWeek)
	{// 领取周卡
		sGLMgr.GainWeekMonthCard(pChr, 1);
		return true;
	}
	else if(type == en_NGB_WelfareMonth)
	{// 领取月卡
		sGLMgr.GainWeekMonthCard(pChr, 2);
		return true;
	}
	
	AICreatureBaseInterface* pAIChar = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if(pAIChar)
	{
		pAIChar->GainGift(type, data1);
	}
	
	return true;
}
//-----------------------------------------------------------------------
bool script_world_process_basemissionlist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
		
	if(sProtocolsMgr.CreateMissionListPacket(&packet, pChr))
		socket->SendPacket(&packet);
	
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_runsmallgame(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	SMGameData smgame;
	packet >> smgame.id >> smgame.status >> smgame.model_id >> smgame.num >> smgame.data1 >> smgame.data2;
using namespace AIScript;
	
	Log.Notice("script_world_process_runsmallgame","id[%u] status[%u] model_id[%u] num[%u]",smgame.id,smgame.status,smgame.model_id,smgame.num);
	
AICreatureBaseInterface *pAiChrInfe = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if(pAiChrInfe)
	{
		if(!pAiChrInfe->RunGame(smgame))
		{
			WorldPacket newP;
			if(sProtocolsMgr.CreateSmallGameDataPacket(&newP, smgame.id, 0, 0,smgame.data1,smgame.data2));
				socket->SendPacket(&newP);
		}
	}
	
	return true;
}

// 兑换背包
bool SERVER_DECL script_world_process_exchangebag(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode, 4))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	if (sProtocolsMgr.CreateExchangeBagPacket(&packet, pChr))
		socket->SendPacket(&packet);
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_openbackpack(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode, 4))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	if (sProtocolsMgr.CreateOpenBackpackPacket(&packet, pChr))
		socket->SendPacket(&packet);
	// 剩余猜拳次数
	if(sVipCardMgr.CreateUpdateMorraNum(&packet, pChr))
		socket->SendPacket(&packet);
	return true;
}
//-----------------------------------------------------------------------
bool script_world_process_transfer(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if(pUser.isNull())
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint16 sev, gameid, cmdid;
	String szSign;
	packet >> sev >> gameid >> cmdid;
	GetPacketString<uint8>(&packet, szSign);
	if(gameid == 1000)
	{// 特殊中转,用于请求背包等数据
		if(cmdid == CMSG_OPENBACKPACK)
		{
			if (sProtocolsMgr.CreateOpenBackpackPacket(&packet, pChr))
				socket->SendPacket(&packet);
		}
	}
	else
	{	
		sDataTranMgr.RecevingTransfer(pUser, gameid, cmdid, szSign);
	}
	
	return true;
}
//-----------------------------------------------------------------------
bool script_world_process_checkversion(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	String pName;
	GetPacketString<uint8>(&packet, pName);
	StringUtil::toUpperCase(pName);
	if (!pName.empty())
	{
		std::map<String, GZIDInfo> mapGZIDInfo = sXmlDataMgr.GetGZIDInfo();
		std::map<String, GZIDInfo>::iterator iter = mapGZIDInfo.find(pName);
		if (iter == mapGZIDInfo.end())
		{
			// compatible early mobile version
			std::vector<String> vecStr = StringUtil::split(pName,".");
			if (vecStr.size() == 2)
			{
				iter = mapGZIDInfo.find("QQ");
				if (iter == mapGZIDInfo.end())
				{
					iter = mapGZIDInfo.begin();
				}
			}
		}
		if (iter != mapGZIDInfo.end())
		{
			if (sProtocolsMgr.CreateCheckVersionResultPacket(&packet, iter->second))
				socket->SendPacket(&packet);
		}
	}
	return true;
}
//-----------------------------------------------------------------------
bool script_world_process_getterminalinfo(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	UserPtr pUser = socket->getCurrentUser();
	if(pUser.isNull())
		return true;
	String info;
	GetPacketString<uint16>(&packet, info);
	String::size_type index = 0;
	while((index = info.find("~",index)) != String::npos)
	{
		info.replace(index, 1, ":");
	}
	Json::Reader reader; 
	Json::Value json_object; 
	if (reader.parse(info.c_str(), json_object))
	{
		if (info.find("{") == 0)
		{
			if (json_object.isMember("mobile") && json_object["mobile"].isMember("version"))
			{
				pUser->setStringField("user_data", json_object["mobile"]["version"].asString());
			}
			pUser->setStringField("server_data", info);
			pUser->SaveDB();
		}
	}
	return true;
}

bool script_world_process_useprop(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;		
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint32 propid, data1, data2, data3;	
	packet >> propid >> data1 >> data2 >> data3;
	AICreatureBaseInterface * pAIChar = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if (pAIChar == NULL)
		return true;
	ChannelPtr pChannel = pAIChar->GetChannelPtr();
	if (pChannel.isNull())	
		return true;
	AIChannelBaseInterface * pAIChan = TO_CHANNEL_BASE_INTERFACE(pChannel->getAIInterface());
	if (pAIChan == NULL)
		return true;
		
	bool re = pAIChan->UseItem(pChr, propid, data1, data2, data3);	
	if (sProtocolsMgr.CreateUsePropPacket(&packet, pChr->getHandle(), propid, re))
		pAIChan->BroadcastPacket(&packet);
	
	return true;
}

bool script_world_process_checklecard(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	AICreatureBaseInterface * pAIChar = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if(!pAIChar)
		return true;
	
	String strCode;
	GetPacketString<uint8>(&packet,strCode);
	
	uint8 re = pAIChar->CheckLECard(strCode);
	if(sProtocolsMgr.CreateCheckLeCardResultPacket(&packet,re))
		socket->SendPacket(&packet);
	
	return true;
}

// 领取乐码
bool SERVER_DECL script_world_process_getlecard(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if(pUser.isNull())
		return true;
	
	uint32 nowtime = time(0);
	uint32 getLemaTime = sBankMgr.GetPublicData(pUser, en_PublicData_GetLemaTime);
	
	if (getLemaTime && sTools.IsSameWeek(nowtime,getLemaTime))	//领取时间判断
		return true;
	
	AICreatureBaseInterface * pAIChar = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if(!pAIChar)
		return true;
	
	uint8 re = pAIChar->CreateLECardToChar();
	if(sProtocolsMgr.CreateGetLeCardsResultPacket(&packet,re))
		socket->SendPacket(&packet);
	
	return true;
}

bool SERVER_DECL script_world_process_updatebody(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	AICreatureBaseInterface* pAICharBaseInf = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if (pAICharBaseInf == NULL)
		return true;
	uint16 bodyid = 0;
	packet >> bodyid;
	if ((bodyid >= 500 && bodyid < 530) || 
		(bodyid >= 400 && bodyid < 430) || 
		pAICharBaseInf->HaveCreatureBody(bodyid))
	{
		pChr->setUInt32Field("id", bodyid);		
		pChr->SaveDB();
	}
	
	return true;
}

//乐币换积分
bool script_world_process_lebichangescore(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint32 coins;
	packet >> coins;
	
	sGLMgr.PutCoins(pChr,coins);
	return true;
}

//积分换铜钱
bool script_world_process_scorechangecoins(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint32 score;
	packet >> score;
	
	sGLMgr.ChangeCoins(pChr,score);
	return true;
}

bool script_world_process_shardgraphics(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint8 flag = 0;
	uint32 data1 = 0, data2 = 0;
	packet >> flag >> data1>>data2;
	AICreatureBaseInterface * pAIChr = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if(pAIChr)
	{
		ChannelPtr pChannel = pAIChr->GetChannelPtr();
		if(pChannel.isNull())
		{
			Log.Debug("script_world_process_graphicend Test", "script_world_process_graphicend pChr[%u] error!", pChr->getHandle());
			return true;
		}
		
		AIChannelBaseInterface * pChnBI = TO_CHANNEL_BASE_INTERFACE(pChannel->getAIInterface());
		if(pChnBI)
		{
			if (sProtocolsMgr.CreateGraphicsPacket(&packet, flag, data1, data2))
			{
				pChnBI->BroadcastPacket(&packet);
			}			
		}
	}
	return true;
}

bool script_world_process_flower(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint32 prop, target, data1;
	packet >> prop >> target >> data1;
	CharPtr pTarget = sCharMgr.getByHandle(target);
	if(pTarget.isNull())
	{
		if(sProtocolsMgr.CreateOperatorPropPacket(&packet, 0))
			socket->SendPacket(&packet);
		return true;
	}
	
	AICreatureBaseInterface * pAIChar = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if(pAIChar == NULL)
		return true;
	
	ChannelPtr pChannel = pAIChar->GetChannelPtr();
	if(pChannel.isNull())
	{
		if(sProtocolsMgr.CreateOperatorPropPacket(&packet, 0))
			socket->SendPacket(&packet);
		return true;
	}
		
	// 鲜花1004,鸡蛋1003
	uint32 price = sXmlDataMgr.GetConfXMLValue("TABLE_PROP_PRICE");
	if(!sGLMgr.reduceItemNum(pChr, ItemModel_Coins, price))
	{
		if(sProtocolsMgr.CreateOperatorPropPacket(&packet, 0))
			socket->SendPacket(&packet);
		
		return true;
	}	
	
	AIChannelBaseInterface * pAIChan = TO_CHANNEL_BASE_INTERFACE(pChannel->getAIInterface());
	if(sProtocolsMgr.CreateOperatorPropPacket(&packet, 1, pChr->getHandle(), prop, pTarget->getHandle(), data1))		
		pAIChan->BroadcastPacket(&packet);
	
	char pStr[512] = "";
	if(prop == ItemModel_Egg)
	{
		sprintf(pStr, sMsg.getMessage("OPERATOR_PROP1").c_str(), 
			pChr->getStringField("name").c_str(), pTarget->getStringField("name").c_str());
	}
	else if(prop == ItemModel_Flower)
	{
		sprintf(pStr, sMsg.getMessage("OPERATOR_PROP2").c_str(), 
			pChr->getStringField("name").c_str(), pTarget->getStringField("name").c_str());
	}
	
	if(sProtocolsMgr.CreateLocalMessagePacket(&packet, pStr, sMsg.getType("OPERATOR_PROP1")))
	{
		pAIChan->BroadcastPacket(&packet);
	}
		
	return true;
}

bool SERVER_DECL script_world_process_system(ResourcePtr & sock,WorldPacket & packet)
{
	return true;
}

// 请求退出游戏(把资产数据拷贝到银行)
bool SERVER_DECL script_world_process_exitgameserver(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	socket->setCheckTimetOut(true);
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	Log.Debug("script_world_process_exitgameserver", "111 can leaveGameSev ");	
	uint32 platform_id = 0, gz_id = 0, ts = 0;
	packet >> platform_id >> gz_id >> ts;
	String info;
	GetPacketString<uint8>(&packet, info);
	Log.Debug("script_world_process_exitgameserver", "222 can leaveGameSev platform_id[%u] gz_id[%u]",platform_id, gz_id);	
	char str[512] = "";
	sprintf(str, "%u%s%u%u", gz_id, PROCESS_SIGN_CODE, platform_id, ts);
	CMD5 md5;
	if (platform_id == 0 || info != md5.GenerateMD5(str))
	{
		Log.Debug("script_world_process_exitgameserver", "333 can leaveGameSev info[%s] md5[%s] gz_id[%u] ts[%u]", 
			info.c_str(), md5.GenerateMD5(str).c_str(), gz_id, ts);	
		return true;
	}
	
	std::list<UserPtr> lstUser;
	sUserMgr.getUserList(&lstUser, 0, 1, "platform_id = %u AND `gz_id`=%u", platform_id, gz_id);
	if (lstUser.empty())
		return true;
	
	UserPtr pUser = lstUser.front();
	if (pUser.isNull())
		return true;
	
	CharPtr pChr = sCharMgr.getByHandle(pUser->getUInt32Field("char_id"));
	if(!pChr.isNull())
	{
		// 离开服务器前游戏内自己做的一些事情
		sGLMgr.DoSomethingBeforeExitGameServer(pChr);
	}
	
	// uint32 gz_id = pUser->getUInt32Field("gz_id");
	bool result = sBankMgr.LeaveGameServer(pUser, gz_id, gz_id);	
	{
		if (sock->getHandle() != pUser->m_Socket._handle && result && !pUser->m_Socket.isNull())
		{
			WSSocketPtr pSocket = pUser->m_Socket.getResourcePtr();
			if (!pSocket.isNull()){
				pSocket->Disconnect();
			}
		}
	}
	
	if(sBankMgr.CreateExitGameResult(&packet, result, gz_id))
		socket->SendPacket(&packet);		
	Log.Debug("script_world_process_exitgameserver", "777 can leaveGameSev pUser[%u] result[%u]", pUser->getHandle(), result);			
	return true;
}

// 请求退出游戏EX(把资产数据拷贝到银行)
bool SERVER_DECL script_world_process_exitgameserverex(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	socket->setCheckTimetOut(true);
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	Log.Debug("script_world_process_exitgameserverex", "111 can leaveGameSev ");	
	uint32 platform_id = 0, gz_id = 0, ts = 0;
	packet >> platform_id >> gz_id >> ts;
	String info;
	GetPacketString<uint8>(&packet, info);
	Log.Debug("script_world_process_exitgameserverex", "222 can leaveGameSev platform_id[%u] gz_id[%u]",platform_id, gz_id);	
	char str[512] = "";
	sprintf(str, "%u%s%u%u", gz_id, PROCESS_SIGN_CODE, platform_id, ts);
	CMD5 md5;
	if (platform_id == 0 || info != md5.GenerateMD5(str))
	{
		Log.Debug("script_world_process_exitgameserverex", "333 can leaveGameSev info[%s] md5[%s] gz_id[%u] ts[%u]", 
			info.c_str(), md5.GenerateMD5(str).c_str(), gz_id, ts);	
		return true;
	}
	
	std::list<UserPtr> lstUser;
	sUserMgr.getUserList(&lstUser, 0, 1, "platform_id = %u AND `gz_id`=%u", platform_id, gz_id);
	if (lstUser.empty())
		return true;
	
	UserPtr pUser = lstUser.front();
	if (pUser.isNull())
		return true;
	
	CharPtr pChr = sCharMgr.getByHandle(pUser->getUInt32Field("char_id"));
	if(!pChr.isNull())
	{
		// 离开服务器前游戏内自己做的一些事情
		sGLMgr.DoSomethingBeforeExitGameServer(pChr);
	}
	
	// uint32 gz_id = pUser->getUInt32Field("gz_id");
	bool result = sBankMgr.LeaveGameServer(pUser, gz_id, gz_id);	
	{
		if (sock->getHandle() != pUser->m_Socket._handle && result && !pUser->m_Socket.isNull())
		{
			WSSocketPtr pSocket = pUser->m_Socket.getResourcePtr();
			if (!pSocket.isNull()){
				pSocket->Disconnect();
			}
		}
	}
	
	if(sBankMgr.CreateExitGameResult(&packet, result, gz_id))
		socket->SendPacket(&packet);		
	Log.Debug("script_world_process_exitgameserverex", "777 can leaveGameSev pUser[%u] result[%u]", pUser->getHandle(), result);			
	return true;
}

bool SERVER_DECL script_world_process_signin(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if (pUser.isNull())
		return true;
	uint8 opType, data1;
	packet >> opType >> data1;
	if (!sBankMgr.GetOrSignin(pUser, opType, data1))
	{
		if (sBankMgr.CreateSigninResultPacket(&packet, opType, data1))
			socket->SendPacket(&packet);
	}
	return true;
}

// 中秋活动
bool SERVER_DECL script_world_process_zhongqiu_activity(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if(pUser.isNull())
		return true;
	stCommonActivity stActi = sXmlDataMgr.GetCommonActivity(pUser->getUInt32Field("reg_from"), 1);
	if(!stActi.type)
		return true;
	uint32 time_now = time(0);
	uint32 begin_time = stActi.begin_time;
	uint32 end_time = stActi.end_time;
	if(begin_time && time_now < begin_time)
		return true;
	if(end_time && time_now > end_time)
		return true;
	AICreatureBaseInterface* pAIChar = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if(pAIChar)
	{
		uint32 last_getTime = pAIChar->GetXMLData("ZHONGQIU_GET_TIME");
		if (!sTools.IsSameDay(last_getTime, time_now) && stActi.daily)
		{// 重置分享领取次数
			pAIChar->SetXMLData("ZHONGQIU_GET", 0);
		}
		
		uint32 isGet = pAIChar->GetXMLData("ZHONGQIU_GET");
		if (isGet < stActi.finish_count)
		{// 还可以给出奖励
			pAIChar->AddXMLValue("ZHONGQIU_GET", 1);
			pAIChar->SetXMLData("ZHONGQIU_GET_TIME", time(0));
			
			std::map<uint32, uint32>::iterator iter, ei = stActi.mapBounties.end();
			for(iter = stActi.mapBounties.begin(); iter!=ei; ++iter)
			{
				sGLMgr.addItemNum(pChr, iter->first, iter->second);
				sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Hortation, iter->first, en_UNT_Add, iter->second, en_HSI_ZhongQiuActivity);
			}
			
			if(sProtocolsMgr.CreateZhongQiuActivityPacket(&packet, enZhongQiuActivityResult_Sucess))
				socket->SendPacket(&packet);
		}
		else
		{// 已经领完
			if(sProtocolsMgr.CreateZhongQiuActivityPacket(&packet, enZhongQiuActivityResult_Failed))
				socket->SendPacket(&packet);
		}
	}
	
	return true;
}

// 我的牧场
bool SERVER_DECL script_world_process_myfarm(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if (pUser.isNull())
		return true;
	
	Log.Debug("script_world_process_myfarm","char[%u]", pChr->getHandle());
	sCenterHappyFarmMgr.GetHappyFarmList(pUser);
	return true;
}
// 买卖牲畜
bool SERVER_DECL script_world_process_buyfarm(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if (pUser.isNull())
		return true;
	uint8 opType = 0;
	uint32 farmId = 0;
	uint16 num = 0;
	packet >> opType >> farmId >> num;
	if(opType)
	{// 卖
		sCenterHappyFarmMgr.SellAnimal(pUser, farmId);
	}
	else
	{// 买
		sCenterHappyFarmMgr.BuyAnimal(pUser, farmId, num);
	}
	
	Log.Debug("script_world_process_buyfarm","char[%u] opType[%u] farmId[%u] num[%u]", pChr->getHandle(), opType, farmId, num);
	return true;
}
// 赠送
bool SERVER_DECL script_world_process_givingfarm(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if (pUser.isNull())
		return true;
	
	uint32 pid, farmId;
	packet >> pid >> farmId;
	
	Log.Debug("script_world_process_givingfarm","char[%u] pid[%u] farmId[%u]", pChr->getHandle(), pid, farmId);
	sCenterHappyFarmMgr.TransAnimal(pUser, pid, farmId);
	return true;
}

// 赠送记录
bool SERVER_DECL script_world_process_givingrecode(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if (pUser.isNull())
		return true;
	
	if (sCenterHappyFarmMgr.CreateGivingRecodePacket(&packet, pUser->getUInt32Field("platform_id")))
		socket->SendPacket(&packet);	
	return true;
}

bool SERVER_DECL script_world_process_buyfarmList(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	if (sBankMgr.CreateBuyFarmListPacket(&packet))
		socket->SendPacket(&packet);
	return true;
}

// 赠送钻石
bool SERVER_DECL script_world_process_givediamand(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if(pUser.isNull())
		return true;
	
	uint32 platform_id;
	uint32 model_id;
	uint32 num;
	
	packet >> platform_id >> model_id >> num;
	Log.Debug("script_world_process_givediamand","pid[%u] player send pid[%u] model_id[%u] num[%u]",
									pUser->getUInt32Field("platform_id"), platform_id, model_id, num);
	
	// 目前只支持钻石和金券
	if(model_id != ItemModel_DiamondOpen && model_id != ItemModel_GoldTicket)
		return true;
	
	sGLMgr.SendItemToUser(pChr, platform_id, model_id, num);
	return true;
}

// 赠送获赠记录信息
bool SERVER_DECL script_world_process_giverecvitemlogs(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if(pUser.isNull())
		return true;
	
	if(sProtocolsMgr.CreateGiveRecvItemLogsPacket(&packet, pUser->getUInt32Field("platform_id")))
		socket->SendPacket(&packet);
	
	return true;
}

bool SERVER_DECL script_world_process_cdkey(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if (pUser.isNull())
		return true;
	String strCdkeyTemp;
	GetPacketString<uint8>(&packet, strCdkeyTemp);	
	
	String strCdkey = ServerDatabase.EscapeString(strCdkeyTemp);	
	uint32 result = 1;
	std::map<uint16, uint32> mapItems;
	// 当前兑换码未领取
	 uint32 count = sItemMgr.getExchangeDBCount("`token` = '%s' AND `status` = 2", strCdkey.c_str());
	if (count > 0)
	{
		if (sProtocolsMgr.CreateUserExchangePacket(&packet, 3, mapItems))
			socket->SendPacket(&packet);
		Log.Debug("script_world_process_cdkey", "strCdkey[%s] count[%u]", strCdkey.c_str(), count);
		return true;
	}
	
	// Log.Debug("script_world_process_cdkey", "aaaa");
	uint32 nt = time(0);
	GameExchange exchange;	
	if (sItemMgr.getExchangeDB(strCdkey, &exchange))
	{
		uint32 platform_id = pUser->getUInt32Field("platform_id");
		uint32 gz_id = pUser->getUInt32Field("gz_id");
		if (exchange.data1 && gz_id != exchange.data1)
		{
			if (sProtocolsMgr.CreateUserExchangePacket(&packet, 2, mapItems))
				socket->SendPacket(&packet);
			return true;
		}
		
		if (exchange.data3 != 0)
		{// 是否已领取同类型兑换码（只需要针对玩家分区进行区分）
			String curr_date = sTools.GetCurDateTime();
			std::list<GameExchange> lstExchanges;
			sItemMgr.getExchangeListDB(&lstExchanges, 0, 1, "`status`=2 AND data1 = %u AND `token_user`=%u AND `data3`=%u ORDER BY `token_time` desc",
									gz_id,platform_id,exchange.data3);
			if (!lstExchanges.empty())
			{				
				GameExchange tmpExc = lstExchanges.front();
				uint32 old_time = sTools.GetDateTimeSeconds(tmpExc.token_time);	
				bool isOk = true;
				if (exchange.data4 == 7)
				{// 每周
					if (sTools.IsSameWeek(nt, old_time))
						isOk = false;
				}
				else if (exchange.data4 == 30)
				{
					if (sTools.IsSameMonth(nt, old_time))
						isOk = false;
				}
				else
				{
					uint32 dayNum = sTools.GetDifferDay(old_time, nt);		
					if (dayNum < (uint32)tmpExc.data4)
						isOk = false;
				}
				if (!isOk)
				{
					if (sProtocolsMgr.CreateUserExchangePacket(&packet, 3, mapItems))
						socket->SendPacket(&packet);
					Log.Debug("script_world_process_cdkey", "platform_id[%u] Sleep time is not!",platform_id);
					return true;
				}
			}
		}		
		// Log.Debug("script_world_process_cdkey", "bbbb");
		uint32 end_time = sTools.GetDateTimeSeconds(exchange.end_time);
		if (exchange.status == 1 && (end_time == 0 || nt < end_time))
		{// 有效
			
			// Log.Debug("script_world_process_cdkey", "cccc");
			if (exchange.item_model1){
				mapItems.insert(std::make_pair(exchange.item_model1, exchange.item_num1));
			}
			if (exchange.item_model2){
				mapItems.insert(std::make_pair(exchange.item_model2, exchange.item_num2));
			}
			if (exchange.item_model3){
				mapItems.insert(std::make_pair(exchange.item_model3, exchange.item_num3));
			}
			if (exchange.item_model4){
				mapItems.insert(std::make_pair(exchange.item_model4, exchange.item_num4));
			}
			// 加物品
			result = 0;
			std::map<uint16, uint32>::iterator iter, enditer = mapItems.end();
			for (iter = mapItems.begin(); iter != enditer; ++ iter)
			{
				sGLMgr.addItemNum(pChr, iter->first, iter->second);
				sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Exchange, iter->first, en_UNT_Add, iter->second);
			}			
			exchange.status = 2;
			exchange.source = pUser->getUInt32Field("platform_id");
			exchange.token_user = pUser->getUInt32Field("platform_id");
			exchange.token_time = sTools.GetCurDateTime();
			exchange.data2 = pUser->getUInt32Field("gz_id");
			exchange.sdata1 = pUser->getStringField("addr");
			exchange.sdata2 = pUser->getStringField("ip");			
			sItemMgr.updateExchangeDB(&exchange);
			// 增加兑换日志
			GameLog *pLog = sChannelMgr.newDumyCenterLog();
			if(NULL != pLog)
			{
				pLog->status = 1;
				pLog->type = 100;
				pLog->src_id = pUser->getUInt32Field("platform_id");
				pLog->sub_type = pUser->getUInt32Field("gz_id");
				pLog->dest_id = exchange.data3;		// 兑换卡类型
				pLog->data1 = exchange.item_model1;	// 物品1
				pLog->data2 = exchange.item_num1;
				pLog->data3 = exchange.item_model2;	// 物品2
				pLog->data4 = exchange.item_num2;
				pLog->data5 = exchange.item_model3;	// 物品3
				pLog->data6 = exchange.item_num3;
				pLog->data7 = exchange.data1;		
				pLog->sdata1 = pUser->getStringField("nick");
				pLog->sdata2 = exchange.name;
				pLog->sdata3 = exchange.token;
				pLog->sdata4 = pUser->getStringField("ip");
				pLog->sdata5 = pUser->getStringField("addr");
				
				pLog->create_time = sTools.GetCurDateTime();
				sChannelMgr.addCenterLogDB(pLog);
				sChannelMgr.freeDumyCenterLog(pLog);
			}
			else
			{
				sChannelMgr.freeDumyLog(pLog);
			}
			
		}
		else 
			result = 2;
		// Log.Debug("script_world_process_cdkey", "dddd");
	}
	if (sProtocolsMgr.CreateUserExchangePacket(&packet, result, mapItems))
		socket->SendPacket(&packet);
	return true;
}

// 获取JSON格式任务列表
bool SERVER_DECL script_process_getcommon_jsonmissionlist(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	if(sProtocolsMgr.CreateCommonJsonMissionListPacket(&packet,pChr))	
		socket->SendPacket(&packet);
	
	return true;
}

// 领取JSON格式任务奖励
bool SERVER_DECL script_process_getcommon_jsonmissionbounty(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint32 model_id;
	packet >> model_id;
	Log.Debug("script_process_getcommon_jsonmissionbounty","char[%u] get mission id[%u] bounty!",pChr->getHandle(),model_id);
	
	bool re = sGLMgr.GetJsonMissionBounty(pChr,model_id);
	if(sProtocolsMgr.CreateGetJsonMissionBountyPacket(&packet,model_id,re))
		socket->SendPacket(&packet);
	return true;
}

// 获取json成就格式的列表
bool SERVER_DECL script_process_getcommon_jsoneffectlist(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;

	Log.Debug("script_process_getcommon_jsoneffectlist","char[%u] get effect list!",pChr->getHandle());
	
	if(sProtocolsMgr.CreateCommonJsonEffectListPacket(&packet,pChr))
		socket->SendPacket(&packet);
	return true;
}

// 领取JSON格式成就奖励
bool SERVER_DECL script_process_getcommon_jsoneffectbounty(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if (pUser.isNull())
		return true;
	
	uint32 model_id = 0;
	uint32 gz_id = 0;
	
	packet >> model_id >> gz_id;
	Log.Debug("script_process_getcommon_jsoneffectbounty","char[%u] get effect id[%u] gz_id[%u] bounty!",pChr->getHandle(), model_id, gz_id);
	
	bool re = false;
	if(gz_id == 0)
	{// 当前服务器直接调用
		re = sGLMgr.GetJsonEffortBounty(pChr,model_id);
	}
	else
	{// 向指定服务器调用
		Json::Value valData;
		
		valData["platform_id"] = pUser->getUInt32Field("platform_id");
		valData["model_id"] = model_id;
		valData["gz_id"] = gz_id;
		valData["agent_id"] = pUser->getUInt32Field("reg_from");
		
		Json::FastWriter w;
		String strData = w.write(valData);
		re = sGLMgr.SendGetEffortBountyByGateway(pChr, strData);
	}
	
	if(sProtocolsMgr.CreateGetJsonEffectBountyPacket(&packet, model_id, re))
		socket->SendPacket(&packet);
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_getcommonplayertop(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint8 topType;
	packet >> topType;
	
	sGLMgr.GetCommonTopQueue(pChr, pChr->getUInt32Field("gz_id"), topType);
	return true;
}

//-----------------------------------------------------------------------
bool script_world_process_getcommonplayertopnew(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint8 topType;
	uint8 offset;
	uint8 num;
	packet >> topType >> offset >> num;
	
	Log.Debug("script_world_process_getcommonplayertopnew","topType[%u] offset[%u] num[%u]", topType, offset, num);
	sGLMgr.GetCommonTopQueueNew(pChr, pChr->getUInt32Field("gz_id"), topType, offset, num);
	return true;
}

// 转发客户端字符串数据
bool SERVER_DECL script_world_process_handlestringdata(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint8 type;
	uint32 extra_data;
	String strData;
	
	packet >> type >> extra_data;
	GetPacketString<uint16>(&packet, strData);
	
	switch(type)
	{
	case enHandleStringType_Table:			// 牌桌
		{
			AICreatureBaseInterface *pAiChrBInfe = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
			if (pAiChrBInfe == NULL)
				return true;
			
			ChannelPtr pChnnel = pAiChrBInfe->GetChannelPtr();
			if (pChnnel.isNull())
				return true;
			
			AIChannelBaseInterface *pAiChnBInfe = TO_CHANNEL_BASE_INTERFACE(pChnnel->getAIInterface());
			if (!pAiChnBInfe)
				return true;
			
			if(sProtocolsMgr.CreateHandleStringPacket(&packet, type, extra_data, strData))
				pAiChnBInfe->BroadcastPacket(&packet);	
		}
		break;
	case enHandleStringType_Single:			// 单独
		{
			CharPtr pChr = sCharMgr.getByHandle(extra_data); 
			if(pChr.isNull())
				return true;
			
			WSSocketPtr pSocket = pChr->getSocket();
			if(pSocket.isNull())
				return true;
			
			if(sProtocolsMgr.CreateHandleStringPacket(&packet, type, extra_data, strData))
			{
				pSocket->SendPacket(&packet);
				socket->SendPacket(&packet);
			}
		}
		break;
	case enHandleStringType_Hall:			// 大厅
		{
			
		}
		break;
	case enHandleStringType_AllServer:		// 全服
		{
			
		}
		break;
	default:
		break;
	}
	
	return true;
}

// 修改假IP地址
bool SERVER_DECL script_world_process_changesocketip(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if (pUser.isNull())
		return true;
	
	String strIp;
	GetPacketString<uint8>(&packet, strIp);
	
	String orgIp = socket->GetIP();
	
	pUser->setStringField("ip", strIp);
	socket->SetFakeIP(strIp);
	
	String strAddress = sShowIP.searchXMLAddress(pUser->getUInt32Field("platform_id"));
	pUser->setStringField("addr", strAddress == "" ? sShowIP.getAddress(strIp.c_str()) : strAddress);
	pUser->SaveDB();
	
	Log.Debug("script_world_process_changesocketip","user pid[%u] char[%u] real ip[%s] fake ip[%s]", 
							pUser->getUInt32Field("platform_id"), pUser->getUInt32Field("char_id"), socket->GetFakeIP(), socket->GetRealIP());
	return true;
}

// CMSG_GETUSERCONTACT = 0x0064,		// 获取玩家联系信息
bool SERVER_DECL script_world_process_getusercontact(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	Log.Debug("script_world_process_getusercontact","char[%u]", pChr->getHandle());
	sGLMgr.GetUserContactInfo(pChr);
	return true;
}

// CMSG_SETUSERCONTACT = 0x0065,		// 设置玩家联系信息
bool SERVER_DECL script_world_process_setusercontact(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	String strData;
	GetPacketString<uint16>(&packet, strData);
	
	Log.Debug("script_world_process_getusercontact","char[%u] strData[%s]", pChr->getHandle(), strData.c_str());
	sGLMgr.SetUserContactInfo(pChr, strData);
	return true;
}

// 通过PID查询玩家数据
//-------------------------------------------------------------------------
bool SERVER_DECL script_world_process_getplayerinfobypid(ResourcePtr & sock, WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	uint32 pid;
	packet >> pid;
	Log.Debug("script_world_process_getplayerinfobypid","want require pid[%u] player info!",pid);
	
	GameBank bank;
	uint8 re = sBankMgr.GetRealBank(pid, bank);
	if (sProtocolsMgr.CreatePubBankDataPacket(&packet, bank,re))
		socket->SendPacket(&packet);
	
	return true;
}

// 发红包
bool SERVER_DECL script_world_process_awardhongbao(ResourcePtr & sock,WorldPacket & packet)
{
	return true;
	
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if (pUser.isNull())
		return true;
	uint32 hbCoins = 0;
	uint8 hbNum = 0, hbType = 0;	
	packet >> hbCoins >> hbNum >> hbType;
	String talk = "";	
	GetPacketString<uint8>(&packet, talk);
	Log.Error("script_world_process_awardhongbao", "script_world_process_awardhongbao hbNum[%u] hbCoins[%u] hbType[%u]",
													hbNum, hbCoins, hbType);
	AICreatureBaseInterface *pAiChrBInfe = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if (pAiChrBInfe == NULL)
		return true;
	ChannelPtr pChnnel = pAiChrBInfe->GetChannelPtr();
	if (pChnnel.isNull())
		return true;
	AIChannelBaseInterface *pAiChnBInfe = TO_CHANNEL_BASE_INTERFACE(pChnnel->getAIInterface());
	if (!pAiChnBInfe->AwardHongBao(pChr, hbCoins))
		return true;
	GamePubData gpd;
	if (sHBMgr.AwardHongBao(pChr, hbNum, hbCoins, hbType, talk, &gpd))
	{
		// uint32 create_time = sTools.GetDateTimeSeconds(gpd.create_time);
		if (sProtocolsMgr.CreateUpdateHongBaoPacket(&packet, gpd.pd_id, gpd.status, gpd.src_platform_id, gpd.src_nick, gpd.create_time))
			pAiChnBInfe->BroadcastPacket(&packet);
	}
	
	return true;
}
// 抢红包
bool SERVER_DECL script_world_process_grabhongbao(ResourcePtr & sock,WorldPacket & packet)
{
	return true;
	
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if (pUser.isNull())
		return true;
	uint32 hbId = 0;
	packet >> hbId;
	GamePubData gpd;
	uint32 hbNum = sHBMgr.GrabHongBao(pChr, hbId, &gpd);
	if (sProtocolsMgr.CreateGrabHongBaoPacket(&packet, gpd.pd_id, gpd.src_platform_id, gpd.src_nick, gpd.sdata3, hbNum))
		socket->SendPacket(&packet);
	if (hbNum)
	{
		sGLMgr.addItemNum(pChr, ItemModel_Coins, hbNum);
		sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_HongBao, ItemModel_Coins, en_UNT_Add, hbNum, hbId);
	}
	return true;
}
// 请求发红包
bool SERVER_DECL script_world_process_requesthongbao(ResourcePtr & sock,WorldPacket & packet)
{
	return true;
	
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if (pUser.isNull())
		return true;
	if (sProtocolsMgr.CreateHongBaoRequestPacket(&packet, 3))
		socket->SendPacket(&packet);
	// uint32 hbId = 0;
	// packet >> hbId;
	// GamePubData gpd;
	// uint32 hbNum = sHBMgr.GrabHongBao(pChr, hbId, &gpd);
	// if (sProtocolsMgr.CreateGrabHongBaoPacket(&packet, gpd.pd_id, gpd.src_platform_id, gpd.src_nick, hbNum))
		// socket->SendPacket(&packet);
	return true;
}
// 红包历史列表
bool SERVER_DECL script_world_process_hongbaohistory(ResourcePtr & sock,WorldPacket & packet)
{
	return true;
	
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	uint32 hisNum = sXmlDataMgr.GetConfXMLValue("HONGBAO_HISTORY");
	if (hisNum == 0)
		hisNum = 10;
	std::map<uint32, GamePubData> mapGPD;
	sHBMgr.GetHongBaoHistory(&mapGPD, hisNum);
	if (sProtocolsMgr.CreateHongBaoHistoryPacket(&packet, mapGPD))
		socket->SendPacket(&packet);
	return true;
}
// 领取红包详情
bool SERVER_DECL script_world_process_hongbaoknocklist(ResourcePtr & sock,WorldPacket & packet)
{
	return true;
	
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if (pUser.isNull())
		return true;
	uint32 hbId = 0;
	packet >> hbId;
	std::list<HongBaoDetail> lstDetail;
	sHBMgr.GetHongBaoDetail(hbId, lstDetail);
	if (sProtocolsMgr.CreateHongBaoKnocklistPacket(&packet, hbId, lstDetail))
		socket->SendPacket(&packet);
	return true;
}
//-----------------------------------------------------------------------
bool SERVER_DECL script_world_process_hongbaotoplist(ResourcePtr & sock,WorldPacket & packet)
{
	return true;
	
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	std::list<HongBaoTop> lstHBTops;
	sHBMgr.GetHongBaoTopList(&lstHBTops);
	if (sProtocolsMgr.CreateHongBaoTopListPacket(&packet, lstHBTops))
		socket->SendPacket(&packet);
	return true;
}
//-----------------------------------------------------------------------
bool SERVER_DECL script_world_process_hongbaocangrablist(ResourcePtr & sock,WorldPacket & packet)
{
	return true;	//屏蔽红包逻辑，有BUG
	
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	UserPtr pUser = sUserMgr.getByHandle(pChr->getUInt32Field("userid"));
	if (pUser.isNull())
		return true;
	uint8 count = 0;
	packet >> count;
	std::map<uint32, GamePubData> mapGpd;
	sHBMgr.GetHongBaoCanGrabList(pUser->getUInt32Field("platform_id"), count, &mapGpd);
	if (sProtocolsMgr.CreateHongBaoCanGrabListPacket(&packet, mapGpd))
		socket->SendPacket(&packet);
	return true;
}

// 更新平台好友列表 0x0084 CMSG_CENTER_UPDATE_PLATFRIENDS
bool SERVER_DECL script_world_process_updateplatfriends(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	std::list<String> lstOpenid;
	
	uint32 gz_id;
	uint16 frd_num;
	packet >> gz_id >> frd_num;
	
	for(uint32 i=0; i<frd_num; ++i)
	{
		String strOpenid;
		GetPacketString<uint8>(&packet, strOpenid);
		
		lstOpenid.push_back(strOpenid);
	}
	
	sCenterFriendsMgr.UpdatePlatformFriends(pChr, gz_id, lstOpenid);
	return true;
}

// 好友列表信息 0x0085 CMSG_CENTER_FRIENDLIST_INFO
bool SERVER_DECL script_world_process_friendslist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint8 type;
	packet >> type;
	
	sCenterFriendsMgr.GetFriendListInfo(pChr, type);
	return true;
}

// 好友信息 0x0086 CMSG_CENTER_FRIEND_INFO
bool SERVER_DECL script_world_process_friendinfo(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 pid;
	packet >> pid;
	
	sCenterFriendsMgr.LookFriendInfo(pChr, pid);
	return true;
}

// 好友操作 0x0087 CMSG_CENTER_OPERATOR_FRIEND
bool SERVER_DECL script_world_process_friendoperator(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint8 opMode;
	uint32 opPid;
	packet >> opMode >> opPid;
	Log.Debug("script_world_process_friendoperator","opMode[%u] opPid[%u]", opMode, opPid);
	
	switch(opMode)
	{
	case enOperatorFriend_Add:	// 添加好友
		{
			sCenterFriendsMgr.RequireFriend(pChr,opPid);
		}
		break;
	case enOperatorFriend_Apply:	// 同意
	case enOperatorFriend_Refuse:	// 拒绝
		{
			sCenterFriendsMgr.AnswerAddFriend(pChr, opPid, opMode);
		}
		break;
	case enOperatorFriend_Delete:	// 删除
		{
			sCenterFriendsMgr.DeleteFriend(pChr, opPid);
		}
		break;
	case enOperatorFriend_Black:	// 拉黑
		{
			sCenterFriendsMgr.BlackFriend(pChr, opPid);
		}
		break;
	default:
		break;
	}
	
	return true;
}

// 提交用户信息到中心 0x0088 CMSG_CENTER_COMMITPLAYERINFO
bool SERVER_DECL script_world_process_commituserinfo(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	String sInfo;
	GetPacketString<uint16>(&packet, sInfo);
	
	uint8 mode;
	packet >> mode;
	
	sFriendRecordMgr.CommitPlayerInfoToCenter(pChr, sInfo, mode);
	return true;
}

// 中心玩家信息 0x0089 CMSG_CENTER_PLAYERINFO
bool SERVER_DECL script_world_process_playeruserinfo(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 pid,gz_id;
	uint8 mode;
	packet >> pid >> gz_id >> mode;
	
	sFriendRecordMgr.GetPlayerCenterInfo(pChr, pid, gz_id, mode);
	return true;
}

// 组局玩家统计信息 0x008C SMSG_CENTER_PLAYERCOUNTINFO
bool SERVER_DECL script_world_process_playercountinfo(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	std::map<uint32, uint32> mapGzid;
	
	uint32 pid;
	uint8 gzidCount;
	packet >> pid >> gzidCount;
	
	for(uint8 i=0; i<gzidCount; ++i)
	{
		uint16 gz_id;
		uint16 mode;
		packet >> gz_id >> mode;
		mapGzid.insert(std::make_pair(gz_id, mode));
	}
	
	sFriendRecordMgr.GetPlayerCenterInfo(pChr, pid, mapGzid);
	return true;
}

// 系统推荐好友列表
bool script_world_process_systemfriends(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	sCenterFriendsMgr.GetSystemFriends(pChr);
	return true;
}


// 申请组局0x00F1
bool SERVER_DECL script_world_process_require_createcenterbattle(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	String strDta;
	GetPacketString<uint16>(&packet, strDta);					// 读取棋牌圈创建数据
	//读取参数，调用函数
	sCenterBattleMgr.PlayerCreateCenterBattle(pChr, strDta);	// 用Json数据创建的方法
	Log.Debug("script_world_process_require_createcenterbattle","char[%u] strData[%s]", pChr->getHandle(), strDta.c_str());
	
	return true;
}

// 请求组局列表信息0x00F2
bool SERVER_DECL script_world_process_centerbattle_list(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	sCenterBattleMgr.SendPlayerCenterBattleListInfo(pChr);
	return true;
}

// 请求组局信息0x00F3
bool SERVER_DECL script_world_process_centerbattle_info(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 cb_id;
	packet >> cb_id;
	
	sCenterBattleMgr.SendPlayerCenterBattleInfo(pChr, cb_id);
	return true;
}

// 请求游戏服务器创建牌桌0x00F4
bool SERVER_DECL script_world_process_centerbattle_create_gamechannel(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	
	uint32 pid;			// 玩家PID
	uint32 cb_id;		// 组局ID
	uint32 gz_id;		// 分区ID
	uint32 update_key;	// 更新数字锁
	
	packet 	>> pid >> cb_id >> gz_id >> update_key;
	Log.Debug("script_world_process_centerbattle_create_gamechannel","pid[%u] cb_id[%u] gz_id[%u] update_key[%u]", 
												pid, cb_id, gz_id, update_key);
	
	sCenterBattleMgr.CreateGameChannel(socket, pid, cb_id, gz_id, update_key);
	return true;
}

// 暂停继续牌桌0x00F6
bool SERVER_DECL script_world_process_centerbattle_operatorchannel(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	
	uint8 mode;
	uint32 cb_id;
	uint32 platform_id;
	uint32 data;
	uint32 update_key;
	
	packet >> platform_id >> mode >> cb_id >> data >> update_key;
	
	Log.Debug("script_world_process_centerbattle_operatorchannel","mode[%u] cb_id[%u] platform_id[%u] data[%u]", 
						mode, cb_id, platform_id, data);
	sCenterBattleMgr.OperatorBattle(socket, platform_id, cb_id, mode, data, update_key);
	return true;
}

// 踢人0x00F7
bool SERVER_DECL script_world_process_centerbattle_kickplayer(ResourcePtr & sock,WorldPacket & packet)
{
	/* WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	
	uint32 platform_id;
	uint32 cb_id;
	uint32 kick_charid;
	
	packet >> platform_id >> cb_id >> kick_charid;
	Log.Debug("script_world_process_centerbattle_kickplayer","platform_id[%u] cb_id[%u] kick_charid[%u]", platform_id, cb_id, kick_charid);
	sCenterBattleMgr.KickPlayer(socket, platform_id, cb_id, kick_charid); */
	return true;
}

// 进入牌桌0x00F8
bool SERVER_DECL script_world_process_centerbattle_joinchannel(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	String join_code;
	GetPacketString<uint8>(&packet, join_code);
	
	uint8 type = 0;
	packet >> type;
	
	Log.Debug("script_world_process_centerbattle_joinchannel","join_code[%s] type[%u]",join_code.c_str(), type);
	
	if(type == 0)
	{// 普通组局场
		sCenterBattleMgr.JoinCenterBattle(pChr, join_code);
	}
	else
	{// 加入比赛场
		
	}
		
	return true;
}


// 获取玩家组局记录 0x00F9
bool SERVER_DECL script_world_process_centerbattle_playerlogs(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 cb_id;
	packet >> cb_id;
	
	sCenterBattleLogMgr.GetPlayerBattleLogs(pChr, cb_id);
	return true;
}

// 获取组局信息记录 0x00FA
bool SERVER_DECL script_world_process_centerbattle_logs(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 cb_id;
	packet >> cb_id;
	
	// 支持请求偏移量版本
	uint16 offset, num;
	packet >> offset >> num;
	
	// sCenterBattleLogMgr.GetBattleLogs(pChr, cb_id);
	sCenterBattleLogMgr.GetBattleLogs(pChr, cb_id, offset, num);
	return true;
}

// 牌局即时输赢0x00FB
bool SERVER_DECL script_world_process_center_battle_currwinlose(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 cb_id;
	packet >> cb_id;
	
	sCenterBattleLogMgr.GetCurrentBattleWinLose(pChr, cb_id);
	return true;
}

// 牌局即时输赢0x00FB
bool SERVER_DECL script_world_process_centerbattle_looplog(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;

	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 cb_id;
	uint8 loop_id;
	packet >> cb_id >> loop_id;
	
	sCenterBattleLogMgr.GetBattleLoopLog(pChr, cb_id, loop_id);
	return true;
}

// 玩家组局行踪
bool SERVER_DECL script_world_process_centerbattle_zujutrack(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	sBankMgr.GetZujuTrackInfo(pChr);
	return true;
}

// 请求游戏录像
bool SERVER_DECL script_world_process_gamerecord_vedio(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint32 cb_id;
	uint8 loop_id;
	packet >> cb_id >> loop_id;
	
	Log.Debug("script_world_process_gamerecord_vedio","cb_id[%u] loop_id[%u]", cb_id, loop_id);
	sCenterBattleLogMgr.GetBattleVedio(pChr, cb_id, loop_id);
	return true;
}

// 评价总信息
bool SERVER_DECL script_world_process_judge_totalinfo(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint32 pid;
	uint32 game_id;
	packet >> pid;
	packet >> game_id;
	
	CRUser cru;
	if(!sCRUsersMgr.GetCRUser(pid, &cru))
		return true;
	
	uint32 total_win = 0;
	uint32 total_count = 0;
	float aver_winScore = 0.0f;
	
	std::list<CenterFriendRecord> lstData;
	if(game_id != 2)
	{
		sFriendRecordMgr.GetCenterFriendRecordList(&lstData,"data4 = %u and pid = %u and status < 255", game_id, pid);
	}
	else
	{
		sFriendRecordMgr.GetCenterFriendRecordList(&lstData,"pid = %u and status < 255", pid);
	}
	
	std::list<CenterFriendRecord>::iterator iter, ei = lstData.end();
	for(iter = lstData.begin(); iter!=ei; ++iter)
	{
		total_win += (*iter).data5;
		total_count += (*iter).data2;
	}
	
	if(total_count == 0)
	{
		aver_winScore = 0.0f;
	}
	else
	{
		aver_winScore = float(total_win) / float(total_count);
	}
	
	// 通过
	if(sProtocolsMgr.CreateJudgeTotalInfoPakcet(&packet, pid, 
													cru.judge_count, 
													cru.judge_total_stars,
													cru.judge_level, 
													cru.start_game_count,
													cru.play_game_count,
													0.5,
													total_win,
													aver_winScore,
													cru.judge_effect_label))
		socket->SendPacket(&packet);
	return true;
}

// 评价结果
bool SERVER_DECL script_world_process_judge_result(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if(pUser.isNull())
		return true;
	
	uint32 pid = pUser->getUInt32Field("platform_id");
	uint32 target_id;
	uint32 target_type;
	uint32 judge_pid;
	uint8 level;
	std::vector<uint8> vLabel;
	uint8 label_num;
	String judge_info;
	
	packet >> target_id >> target_type >> judge_pid >> level >> label_num;
	for(uint8 i=0; i<label_num; ++i)
	{
		uint8 value = 0;
		packet >> value;
		
		Log.Debug("script_world_process_judge_result","label_num[%u] value[%u]", label_num, value);
		vLabel.push_back(value);
	}
	
	GetPacketString<uint8>(&packet, judge_info);
	
	sCenterJudgeMgr.PlayerJudge(pChr, target_id, target_type, pid, judge_pid, level, vLabel, judge_info);
	return true;
}

// 评价详细列表
bool SERVER_DECL script_world_process_judge_list(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if(pUser.isNull())
		return true;
	
	uint32 pid = pUser->getUInt32Field("platform_id");
	uint32 offset;
	uint8 num;
	
	std::list<CenterJudge> lstCJ;
	sCenterJudgeMgr.GetjudgeList(&lstCJ, pid, offset, num);
	
	if(sProtocolsMgr.CreateJudgeInfoListPacket(&packet, pid, offset, num, lstCJ))
		socket->SendPacket(&packet);
	
	return true;
}

// 评价结果信息0x00E4
bool SERVER_DECL script_world_process_judge_resultlist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if(pUser.isNull())
		return true;
	
	uint32 pid = pUser->getUInt32Field("platform_id");
	uint32 target_id, target_type;
	
	packet >> target_id >> target_type;
	Log.Debug("script_world_process_judge_resultlist","pid[%u] target_id[%u] target_type[%u]", pid, target_id, target_type);
	
	sCenterJudgeMgr.GetJudgedCenterBattlePidList(pChr, pid, target_id, target_type);
	return true;
}

// 同意或拒绝进行游戏
bool SERVER_DECL script_world_process_centerbattle_agreeorrefuseplayer(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint8 agree;			// 0,拒绝 1 同意
	packet >> agree;
	
	AICreatureBaseInterface * pAIChar = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if (pAIChar == NULL)
		return true;
	
	ChannelPtr pChannel = pAIChar->GetChannelPtr();
	if (pChannel.isNull())	
		return true;
	
	AIChannelBaseInterface * pAIChan = TO_CHANNEL_BASE_INTERFACE(pChannel->getAIInterface());
	if (pAIChan == NULL)
		return true;
	
	pAIChan->AgreeOrRefusePlayGame(pChr, agree);
	return true;
}

// 选择座位 CMSG_CENTERBATTLE_CHOOSEPOS 0x2002
bool SERVER_DECL script_world_process_centerbattle_playerchooseseat(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint8 seat;			// 座位
	packet >> seat;
	
	AICreatureBaseInterface * pAIChar = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if (pAIChar == NULL)
		return true;
	
	ChannelPtr pChannel = pAIChar->GetChannelPtr();
	if (pChannel.isNull())	
		return true;
	
	AIChannelBaseInterface * pAIChan = TO_CHANNEL_BASE_INTERFACE(pChannel->getAIInterface());
	if (pAIChan == NULL)
		return true;
	
	pAIChan->PlayerChooseASeat(pChr, seat);
	return true;
}

// 发起投票 CMSG_CENTERBATTLE_SENDVOTE 	0x2003
bool SERVER_DECL script_world_process_centerbattle_playersendvote(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	AICreatureBaseInterface * pAIChar = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if (pAIChar == NULL)
		return true;
	
	ChannelPtr pChannel = pAIChar->GetChannelPtr();
	if (pChannel.isNull())	
		return true;
	
	AIChannelBaseInterface * pAIChan = TO_CHANNEL_BASE_INTERFACE(pChannel->getAIInterface());
	if (pAIChan == NULL)
		return true;
	
	pAIChan->PlayerSendVote(pChr);
	return true;
}

// 玩家投票	CMSG_CENTERBATTLE_VOTERESULT 0x2005
bool SERVER_DECL script_world_process_centerbattle_playerdealvote(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	AICreatureBaseInterface * pAIChar = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if (pAIChar == NULL)
		return true;
	
	ChannelPtr pChannel = pAIChar->GetChannelPtr();
	if (pChannel.isNull())	
		return true;
	
	AIChannelBaseInterface * pAIChan = TO_CHANNEL_BASE_INTERFACE(pChannel->getAIInterface());
	if (pAIChan == NULL)
		return true;
	
	uint8 result;				// 投票选择
	packet >> result;
	
	pAIChan->PlayerDealVote(pChr, result);
	Log.Warning("script_world_process_centerbattle_playerdealvote","result[%u]", result);
	return true;
}

// 赠送免费互动道具 0x2010
bool SERVER_DECL script_world_process_givefreegift(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	AICreatureBaseInterface * pAIChar = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
	if (pAIChar == NULL)
		return true;
	
	ChannelPtr pChannel = pAIChar->GetChannelPtr();
	if (pChannel.isNull())	
		return true;
	
	AIChannelBaseInterface * pAIChan = TO_CHANNEL_BASE_INTERFACE(pChannel->getAIInterface());
	if (pAIChan == NULL)
		return true;
	
	uint32 char_id;					// 角色ID
	uint8 gift_id;					// 礼物ID
	packet >> char_id >> gift_id;
	
	pAIChan->GiveFreeGift(pChr, char_id, gift_id);
	return true;
}

// 赠送免费互动道具 0x2011
bool SERVER_DECL script_world_process_require_canjoincenterbattle(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	uint32 platform_id;
	String join_code;
	
	packet >> platform_id;								// PID
	GetPacketString<uint8>(&packet, join_code);			// 进入验证码
	
	/* uint8 result = enResult_Sucess;
	bool bPlaying = false;
	
	TownPtr pJoinTown;
	do
	{
		std::list<ResourcePtr> users;
		sUserMgr.getDBObjects(&users, 0, 1, "platform_id = %u", platform_id);
		if(users.empty())
			return true;
		
		UserPtr pUser = *user.begin();
		if(pUser.isNull())
			return true;
		
		AICreatureBaseInterface * pAiChrInfe = TO_CREATURE_BASE_INTERFACE(pChr->getAIInterface());
		if(!pAiChrInfe)
		{// 接口获取失败
			result = enResult_Failed;
			break;
		}
		
		std::list<CenterBattle> lstData;
		sCenterBattleMgr.GetCenterBattleList(&lstData, "join_code = '%s' and status < 255 ", join_code.c_str());
		
		if(lstData.size() != 1)
		{// 牌桌不存在
			result = enJoinChannel_NoThisBattle;
			break;
		}
		
		CenterBattle cb = *lstData.begin();
		
		std::list<ResourcePtr> objs;
		sUserMgr.getDBObjects(&objs, 0, 1, "platform_id = %u and reg_from = %u", cb.pid, 1017);
		
		if(objs.size() && pUser->getUInt32Field("reg_from") != 1017)
		{// 非指定分区玩家不能进入
			result = enJoinChannel_NoThisBattle;
			break;
		}
		
		TownPtr pTown = pAiChrInfe->GetTown();
		if(!pTown.isNull())
		{// 在其他牌桌
			if(!sXmlDataMgr.IsAIInCenterBattle(cb.game_id, pTown->getUInt32Field("ai")))
			{
				result = enJoinChannel_InOtherChannel;
				break;
			}
		}
		
		ChannelPtr pChannel = pAiChrInfe->GetChannelPtr();
		if (!pChannel.isNull())
		{// 在其他牌桌
			if(!sXmlDataMgr.IsAIInCenterBattle(cb.game_id, pChannel->getUInt32Field("ai"))
					|| join_code.compare(pChannel->getStringField("winner")))
			{
				result = enJoinChannel_InOtherChannel;
				break;
			}
		}
		
		Json::Reader reader;
		Json::Value valP;
		reader.parse(cb.player, valP);
		
		bool bFindChar = false;
		for(Json::Value::iterator iterVal=valP.begin(); iterVal!=valP.end(); ++iterVal)
		{
			if(pUser->getUInt32Field("platform_id") == StringConverter::parseUnsignedInt(iterVal.key().asString()))
			{
				bFindChar = true;
				if((*iterVal)["player_status"] == enCenterBattlePlayerStatus_Playing)
				{
					bPlaying = true;
				}
				break;
			}
		}
		
		// uint32 watch_playerNum = sXmlDataMgr.GetGameWatchMode(cb.reg_from, cb.game_id, cb.data1, cb.mode, cb.limit_loop);
		// if(watch_playerNum == 0)
		// {// 没有观战模式的玩家不能进行已满的房间
			// 游戏开始并且人满新玩家无法进入
			if(cb.status == enBattleStatus_playing && valP.size() >= cb.min_player)
			{// 游戏中状态
				if(!bFindChar || !bPlaying)
				{// 玩家未在游戏中
					result = enJoinChannel_Playing;
					break;
				}
			}
			
			if(!bFindChar && valP.size() >= cb.min_player)
			{// 人数已满自己不在牌桌中
				result = enJoinChannel_PlayerFull;
				break;
			}
		// }
		// else
		// {// 可以观战的时候
			// if(!bFindChar && valP.size() >= cb.min_player + valP.size())
			// {// 算上观战人数，已满
				// result = enJoinChannel_PlayerFull;
				// break;
			// }
		// }
		
		if(result != enResult_Sucess)
			break;
		
	}while(0);
	
	if(sProtocolsMgr.CreateRequireCanJoinCenterBattlePacket(&packet, join_code, result))
		socket->SendPacket(&packet);
	 */
	return true;
}

// 请求组局公共房列表 0x2012
bool SERVER_DECL script_world_process_require_centerbattlepubliclist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if(pUser.isNull())
		return true;
	
	uint32 game_id;
	packet >> game_id;		// 游戏ID
	
	// Log.Debug("script_world_process_require_centerbattlepubliclist","reg_from[%u] game_id[%u]", pUser->getUInt32Field("reg_from"), game_id);
	
	std::list<CenterBattle> vCb = sCenterBattleMgr.GetPublicCenterBattleList(pUser->getUInt32Field("reg_from"), game_id);
	if(sProtocolsMgr.CreateCenterBattlePublicListPacket(&packet, game_id, vCb))
		socket->SendPacket(&packet);
	
	return true;
}

//CMSG_CREATEORJOIN_CENTERBATTLE = 0x2013,	// 创建或者加入随机组局
bool SERVER_DECL script_world_process_createorjoin_centerbattle(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	String strDta;
	GetPacketString<uint16>(&packet, strDta);					// 读取棋牌圈创建数据
	//读取参数，调用函数
	sCenterBattleMgr.CreateOrJoinCenterBattle(pChr, strDta);	// 用Json数据创建的方法
	Log.Debug("script_world_process_createorjoin_centerbattle","char[%u] strData[%s]", pChr->getHandle(), strDta.c_str());
	return true;
}

// 请求斗地主组局列表 0x2014
bool SERVER_DECL script_world_process_ddz_publicbattlelist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	String parmas;
	GetPacketString<uint16>(&packet, parmas);
	sCenterBattleMgr.GetDDZPublicBattleList(pChr, parmas);
	return true;
}

// 请求给斗地主牌桌上锁 0x2015
bool SERVER_DECL script_world_process_ddz_publicbattlelock(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 cb_id;
	String passwd;
	
	packet >> cb_id;
	GetPacketString<uint8>(&packet, passwd);
	
	bool re = sCenterBattleMgr.SetBattlePasswd(cb_id, passwd);
	if(sProtocolsMgr.CreateSetBattleLockResutlPacket(&packet, cb_id, passwd, re))
		socket->SendPacket(&packet);
	
	Log.Debug("script_world_process_ddz_publicbattlelock","cb_id[%u] passwd[%s] re[%u]", cb_id, passwd.c_str(), re);
	return true;
}

//CMSG_CENTER_CHANGECENTERBATTLE = 0x2016 组局换桌
bool SERVER_DECL script_world_process_changecenterbattle(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	Log.Debug("script_world_process_changecenterbattle","char[%u]", pChr->getHandle());
	sCenterBattleMgr.ChangeJoinCenterBattle(pChr);
	return true;
}

// 组局玩家信息0x2020
bool SERVER_DECL script_world_process_centerbattle_playerinfo(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 cb_id;
	packet >> cb_id;
	
	sCenterBattleLogMgr.GetCurrentBattlePlayerInfo(pChr, cb_id);
	return true;
}

// 请求玩家最近N场组局单局记录 0x2021
bool SERVER_DECL script_world_process_centerbattle_singlelogs(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 offset;
	uint16 require_count;
	packet >> offset >> require_count;
	
	sCenterBattleLogMgr.GetPlayerSingleLogs(pChr, offset, require_count);
	return true;
}

// 请求某分区某房间人数 0x2022
bool SERVER_DECL script_world_process_common_requiretownplayercount(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if(pUser.isNull())
		return true;
	
	uint32 gz_id;
	uint32 town_id;
	
	packet >> gz_id >> town_id;
	
	Json::Value val;
	val["gz_id"] = gz_id;
	val["town_id"] = town_id;
	val["agent_id"] = pUser->getUInt32Field("reg_from");
	
	Json::FastWriter w;
	String strData = w.write(val);
	String extra_info = "";
	
	uint32 player_count = sGLMgr.GetRoomPlayerCountByGzid(strData, extra_info);
	if(sProtocolsMgr.CreateTownPlayerCountByGzid(&packet, gz_id, town_id, player_count))
		socket->SendPacket(&packet);
	return true;
}

// CMSG_CENTERBATTLE_MATCHZONELOGS = 0x2023,		// 赛区战绩记录列表
bool SERVER_DECL script_world_process_centerbattle_matchzonelogs(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 zone_id;
	uint32 offset;
	uint16 require_count;
	
	packet >> zone_id >> offset >> require_count;
	Log.Debug("script_world_process_centerbattle_matchzonelogs","char[%u] zone_id[%u] offset[%u] require_count[%u]", pChr->getHandle(), zone_id, offset, require_count);
	
	sCenterBattleLogMgr.GetPlayerMatchZoneLogs(pChr, zone_id, offset, require_count);
	return true;
}

// 操作公共用户信息0x2032
bool SERVER_DECL script_world_process_common_opuserconfiginfo(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 platform_id;
	uint32 gz_id;
	uint8 op_mode;
	
	packet >> platform_id >> gz_id >> op_mode;
	
	String strConfig;
	GetPacketString<uint16>(&packet, strConfig);
	
	
	
	if(op_mode == 1)
	{// 读取，可以是任何人的
		
		std::list<UserPtr> lstUser;
		sUserMgr.getUserList(&lstUser, 0, 1, "platform_id = %u AND `gz_id`=%u", platform_id, gz_id);
		if (lstUser.empty())
			return true;
		
		UserPtr pUser = *lstUser.begin();
		if(pUser.isNull())
			return true;
		
		GameBank pubData;
		sBankMgr.GetPublicData(pUser, &pubData);
		
		if(sProtocolsMgr.CreateCommonUserConfigInfoPacket(&packet, platform_id, gz_id, pubData.info))
			socket->SendPacket(&packet);
	}
	else
	{// 设置，只能是自己的
		UserPtr pUser = socket->getCurrentUser();
		if(pUser.isNull())
			return true;
		
		GameBank pubData;
		sBankMgr.GetPublicData(pUser, &pubData);
		
		pubData.info = strConfig;
		sChannelMgr.updateBankDB(&pubData);
		
		if(sProtocolsMgr.CreateCommonUserConfigInfoPacket(&packet, pUser->getUInt32Field("platform_id"), pUser->getUInt32Field("gz_id"), pubData.info))
			socket->SendPacket(&packet);
	}
	
	return true;
}

// 请求斗地主牌桌列表
bool SERVER_DECL script_world_process_common_ddzchannellist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if(pUser.isNull())
		return true;
	
	String strData;
	GetPacketString<uint8>(&packet, strData);
	
	Json::Value val;
	Json::Reader reader;
	reader.parse(strData, val);
	
	if(val.empty())
		return true;
	
	val["pid"] = pUser->getUInt32Field("platform_id");
	val["gz_id"] = pUser->getUInt32Field("gz_id");
	val["agent_id"] = pUser->getUInt32Field("reg_from");
	
	Json::FastWriter w;
	String strPar = w.write(val);
	
	sGLMgr.GetGameTableListInfoByGateway(strPar);
	return true;
}

// 公共签到
bool SERVER_DECL script_world_process_common_sign(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;	
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if (pUser.isNull())
		return true;
	
	uint8 type;			// 签到类型
	uint8 data;			// 签到索引
	
	packet >> type >> data;
	sBankMgr.GetCommonSign(pUser, type, data);
	return true;
}

// 公共签名
bool SERVER_DECL script_world_process_common_signname(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if (pUser.isNull())
		return true;
	
	uint8 mode;			// 模式（0,设置 1 读取）
	uint32 target_pid;	// 目标玩家PID(0,表示自己）
	String content;		// 内容（如果是读取长度为0）
	
	packet >> mode >> target_pid;
	GetPacketString<uint16>(&packet, content);
	
	content = ServerDatabase.EscapeString(content);
	if(target_pid == 0)
		target_pid = pUser->getUInt32Field("platform_id");
	
	Log.Debug("script_world_process_common_signname","mode[%u] target_pid[%u] content[%s]", mode, target_pid, content.c_str());
	
	if(mode == 0)
	{// 设置
		// 玩家只能设置自己的个性签名
		if(target_pid != pUser->getUInt32Field("platform_id"))
			return true;
		
		sBankMgr.CommonSignName(pChr, target_pid, content);
	}
	else
	{// 读取
		sBankMgr.GetCommonSignName(pChr, target_pid);
	}
	
	return true;
}

/************************************俱乐部相关****************************************/
//CMSG_CLUB_NORMALINFO = 0x2100,	// 俱乐部资料
bool SERVER_DECL script_world_process_club_info(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	packet >> club_id;
	Log.Debug("script_world_process_club_info","char[%u] club_id[%u]", pChr->getHandle(), club_id);
	
	sCenterClubMgr.GetClubNormalInfo(pChr, club_id);
	return true;
}

//CMSG_CLUB_HALLINFO = 0x2101,		// 俱乐部详细信息
bool SERVER_DECL script_world_process_club_totalinfo(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint32 club_id;
	packet >> club_id;
	Log.Debug("script_world_process_club_totalinfo","char[%u] club_id[%u]", pChr->getHandle(), club_id);
	
	sCenterClubMgr.GetClubHallInfo(pChr, club_id);
	return true;
}

//CMSG_CLUB_LIST = 0x2102,			// 请求俱乐部列表（地区查询，名字查询，自己的）
bool SERVER_DECL script_world_process_club_listinfo(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint8 type;
	String strData;
	
	packet >> type;
	GetPacketString<uint8>(&packet, strData);
	strData = ServerDatabase.EscapeString(strData);
	
	Log.Debug("script_world_process_club_listinfo","char[%u] type[%u] strData[%s]", pChr->getHandle(), type, strData.c_str());
	
	switch(type)
	{
	case enClubList_Area:	// 地区查询
		sCenterClubMgr.GetClubListInfo(pChr, strData);
		break;
	case enClubList_Name:	// 名字查询
		sCenterClubMgr.GetClubNormalInfo(pChr, strData);
		break;
	case enClubList_Myself:	// 自己加入的
		sCenterClubMgr.GetSelfClubList(pChr);
		break;
	default:
		break;
	}
	
	return true;
}

//CMSG_CLUB_CREATE = 0x2103,		// 创建俱乐部
bool SERVER_DECL script_world_process_club_create(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 badge_icon;
	String name;
	String city;
	packet >> badge_icon;
	GetPacketString<uint8>(&packet, name);
	GetPacketString<uint8>(&packet, city);
	
	name = ServerDatabase.EscapeString(name);
	city = ServerDatabase.EscapeString(city);
	
	Log.Debug("script_world_process_club_create","char[%u] badge_icon[%u] name[%s] city[%s]", pChr->getHandle(), badge_icon, name.c_str(), city.c_str());
	
	// 创建俱乐部
	sCenterClubMgr.CreateClub(pChr, badge_icon, name, city);
	return true;
}

//CMSG_CLUB_REQUIREJOIN = 0x2104,	// 请求加入俱乐部
bool SERVER_DECL script_world_process_club_requirejoin(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	uint32 referee_id;
	String content;
	
	packet >> club_id >> referee_id;
	GetPacketString<uint8>(&packet, content);
	
	content = ServerDatabase.EscapeString(content);
	
	Log.Debug("script_world_process_club_requirejoin","char[%u] club_id[%u] referee_id[%u] content[%s]", pChr->getHandle(), club_id, referee_id, content.c_str());
	sCenterClubMgr.RequireJoinClub(pChr, club_id, referee_id, content);
	return true;
}

//CMSG_CLUB_REVIEW = 0x2105,		// 审核操作（申请加入/带入金额）
bool SERVER_DECL script_world_process_club_review(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 message_id;		// 消息ID
	uint8 type;				// 类型（1 加入 2 带入）
	uint8 mode;				// 操作（1 同意 2 拒绝）
	
	packet >> message_id >> type >> mode;
	Log.Debug("script_world_process_club_review","char[%u] message_id[%u] type[%u] mode[%u]", pChr->getHandle(), message_id, type, mode);
	
	if(type == enClubMessageType_Review)
		sCenterClubMgr.DealMemberJoinClub(pChr, message_id, mode);
	else if(type == enClubMessageType_Takein)
		sCenterClubMgr.DealTakeinScore(pChr, message_id, mode);
	
	return true;
}

//CMSG_CLUB_REVIEWLOGS = 0x2106,	// 审核历史（加入/带入）
bool SERVER_DECL script_world_process_club_reviewlogs(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	uint8 type;					// 类型（1 审核 2 带入 3 退分）
	packet >> club_id >> type;
	
	Log.Debug("script_world_process_club_reviewlogs","char[%u] club_id[%u] type[%u]", pChr->getHandle(), club_id, type);
	
	sCenterClubLogMgr.GetReviewLogs(pChr, club_id, type);
	return true;
}

//CMSG_CLUB_TAKEIN = 0x2107,		// 玩家请求带入金币
bool SERVER_DECL script_world_process_club_takein(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	uint32 coins;
	packet >> club_id >> coins;
	Log.Debug("script_world_process_club_takein","char[%u] club_id[%u] coins[%u]", pChr->getHandle(), club_id, coins);
	
	sCenterClubMgr.PlayerTakeinScore(pChr, club_id, coins);
	return true;
}

//CMSG_CLUB_RETURNCOINS = 0x2108,	// 退分
bool SERVER_DECL script_world_process_club_returncoins(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 pid = 0;
	uint32 club_id = 0;
	packet >> club_id >> pid;
	Log.Debug("script_world_process_club_returncoins","char[%u] club_id[%u] pid[%u]", pChr->getHandle(), club_id, pid);
	sCenterClubMgr.PlayerReturnScore(pChr, club_id, pid);
	return true;
}

//CMSG_CLUB_BUYPLAYERRANK = 0x2109,	// 购买会员
bool SERVER_DECL script_world_process_club_buyplayerrank(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint8 rank;
	packet >> rank;
	Log.Debug("script_world_process_club_buyplayerrank","char[%u] rank[%u]", pChr->getHandle(), rank);
	
	sCenterClubMgr.PlayerBuyRank(pChr, rank);
	return true;
}

//CMSG_CLUB_BUYCLUBRANK = 0x210A,	// 购买俱乐部星级
bool SERVER_DECL script_world_process_club_buyclubrank(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	uint8 rank;
	packet >> club_id >> rank;
	Log.Debug("script_world_process_club_buyclubrank","char[%u] club_id[%u] rank[%u]", pChr->getHandle(), club_id, rank);
	
	sCenterClubMgr.PlayerBuyClubRank(pChr, club_id, rank);
	return true;
}

//CMSG_CLUB_EXITCLUB = 0x210B,		// 退出公会
bool SERVER_DECL script_world_process_club_exit(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	packet >> club_id;
	Log.Debug("script_world_process_club_exit","char[%u] club_id[%u]", pChr->getHandle(), club_id);
	
	sCenterClubMgr.PlayerExitClub(pChr, club_id);
	return true;
}

//CMSG_CLUB_CHANGEQUANXIAN = 0x210C,// 权限调整
bool SERVER_DECL script_world_process_club_changequanxian(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint32 club_id;
	uint32 pid;				// 操作的玩家ID
	uint8 member_type;		// 成员类型
	
	packet >> club_id >> pid >> member_type;
	Log.Debug("script_world_process_club_changequanxian","char[%u] club_id[%u] pid[%u] member_type[%u]", pChr->getHandle(), club_id, pid, member_type);
	
	sCenterClubMgr.ChangePlayerQuanXian(pChr, club_id, pid, member_type);
	return true;
}

//CMSG_CLUB_KICKOUT = 0x210D,		// 踢出玩家
bool SERVER_DECL script_world_process_club_kickout(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	uint32 pid;
	
	packet >> club_id >> pid;
	Log.Debug("script_world_process_club_kickout","char[%u] club_id[%u] pid[%u]", pChr->getHandle(), club_id, pid);
	
	sCenterClubMgr.KickoutPlayer(pChr, club_id, pid);
	return true;
}

//CMSG_CLUB_CHATLIST = 0x210E,		// 聊天列表信息
bool SERVER_DECL script_world_process_club_chatlist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	uint16 limit_count;
	packet >> club_id >> limit_count;
	Log.Debug("script_world_process_club_chatlist","char[%u] club_id[%u] limit_count[%u]", pChr->getHandle(), club_id, limit_count);
	
	sCenterClubMessageMgr.GetClubChatMessageList(pChr, club_id, limit_count);
	return true;
}

//CMSG_CLUB_CHAT = 0x210F,			// 发送聊天
bool SERVER_DECL script_world_process_club_chat(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	// 禁言后消息返给发言者
	if (IS_CREATURE_FLAG(pChr, en_CreatureFlag_Shutup))
	{
		if(sProtocolsMgr.CreateLocalMessagePacket(&packet, sMsg.getMessage("chat_refuse").c_str(), sMsg.getType("chat_refuse")))
			socket->SendPacket(&packet);
		Log.Debug("script_world_process_club_chat","char[%u] chat refuse!", pChr->getHandle());
		return true;
	}
	
	uint32 club_id;
	String content;
	packet >> club_id;
	
	GetPacketString<uint16>(&packet, content);
	content = ServerDatabase.EscapeString(content);
	
	Log.Debug("script_world_process_club_chat","char[%u] club_id[%u] content[%s]", pChr->getHandle(), club_id, content.c_str());
	sCenterClubMgr.PlayerChat(pChr, club_id, content);
	return true;
}

// CMSG_CLUB_TAKEINMEESAGELIST = 0x2110,		// 俱乐部带入消息列表
bool SERVER_DECL script_world_process_club_takeinmessagelist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;		// 俱乐部ID
	packet >> club_id;
	
	sCenterClubMessageMgr.GetClubTakeinMessages(pChr, club_id);
	Log.Debug("script_world_process_club_takeinmessagelist","char[%u] club_id[%u]", pChr->getHandle(), club_id);
	return true;
}

//CMSG_CLUB_BATTLELIST = 0x2111,		// 请求俱乐部组局列表
bool SERVER_DECL script_world_process_club_battlelist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;		// 俱乐部ID
	packet >> club_id;
	Log.Debug("script_world_process_club_battlelist","char[%u] club_id[%u]", pChr->getHandle(), club_id);
	
	// 发送某个俱乐部组局信息列表
	sCenterBattleMgr.SendClubCenterBattleListInfo(pChr, club_id);
	return true;
}

//CMSG_CLUB_MYCLUBBATTLELIST = 0x2112,// 发现自己俱乐部组局列表
bool SERVER_DECL script_world_process_club_discoverbattlelist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	// 发送某个俱乐部房间信息列表
	sCenterClubMgr.GetMyClubRoomList(pChr);
	return true;
}

//CMSG_CLUB_CHENGJIPAIHANG = 0x2113,	// 俱乐部成绩排行
bool SERVER_DECL script_world_process_club_chengjiorder(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	packet >> club_id;
	
	// 发送某个俱乐部组局信息列表
	sCenterClubMemberMgr.GetMemberListByChengji(pChr, club_id);
	return true;
}


// CMSG_CLUB_ROOMLIST = 0x2114,		// 房间列表
bool SERVER_DECL script_world_process_club_roomlist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	uint8 type;
	packet >> club_id >> type;
	
	Log.Debug("script_world_process_club_roomlist","char[%u] club_id[%u] type[%u]", pChr->getHandle(), club_id, type);
	sCenterClubRoomMgr.GetClubRoomList(pChr, club_id, type);
	return true;
}

// CMSG_CLUB_CREATEROOM = 0x2115,	// 创建房间
bool SERVER_DECL script_world_process_club_createroom(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	packet >> club_id;
	
	String strData;
	GetPacketString<uint16>(&packet, strData);
	
	Log.Debug("script_world_process_club_createroom","char[%u] club_id[%u] strData[%s]", pChr->getHandle(), club_id, strData.c_str());
	sCenterClubRoomMgr.CreateClubRoom(pChr, club_id, strData);
	return true;
}

// CMSG_CLUB_BUYGOODS = 0x2117,		// 购买商品
bool SERVER_DECL script_world_process_club_buygoods(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 goods_id;
	packet >> goods_id;
	
	Log.Debug("script_world_process_club_buygoods","goods_id[%u]", goods_id);
	sCenterClubMgr.BuyClubGoods(pChr, goods_id);
	return true;
}

// CMSG_CLUB_PLAYERINFO = 0x2118,	// 俱乐部玩家信息
bool SERVER_DECL script_world_process_club_playerinfo(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	if(sProtocolsMgr.CreateClubPlayerInfoPacket(&packet, pChr))
		socket->SendPacket(&packet);
	return true;
}

// CMSG_CLUB_CURRSCORE = 0x02119,	// 俱乐部当前积分
bool SERVER_DECL script_world_process_club_currscore(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if(pUser.isNull())
		return true;
	
	uint32 club_id;
	packet >> club_id;
	
	uint32 pid = pUser->getUInt32Field("platform_id");
	Log.Debug("script_world_process_club_currscore","char[%u] club_id[%u] pid[%u]", pChr->getHandle(), club_id, pid);
	
	uint32 curr_score = sCenterClubMemberMgr.GetMemberCurrCoins(club_id, pChr);
	if(sProtocolsMgr.CreateClubPlayerCurrScorePacket(&packet, club_id, curr_score))
		socket->SendPacket(&packet);
	
	return true;
}

// CMSG_CLUB_DISSOLVE = 0x211A,			// 解散俱乐部
bool SERVER_DECL script_world_process_club_dissolve(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	packet >> club_id;
	Log.Debug("script_world_process_club_dissolve","char[%u] club_id[%u]", pChr->getHandle(), club_id);
	
	// 解散公会
	sCenterClubMgr.DissolveClub(pChr, club_id);
	return true;
}

// CMSG_CLUB_CHANGECLUBINFO = 0x211B,	// 修改俱乐部信息
bool SERVER_DECL script_world_process_club_changeinfo(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	uint8 type;
	packet >> club_id >> type;
	
	String strData;
	GetPacketString<uint16>(&packet, strData);
	
	Log.Debug("script_world_process_club_changeinfo","char[%u] club_id[%u] type[%u] strData[%s]", pChr->getHandle(), club_id, type, strData.c_str());
	sCenterClubMgr.ChangeClubInfo(pChr, club_id, type, strData);
	return true;
}

// CMSG_CLUB_REMARKINFO = 0x211C,			// 玩家备注信息
bool SERVER_DECL script_world_process_club_playerremarkinfo(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	Log.Debug("script_world_process_club_playerremarkinfo","char[%u]", pChr->getHandle());
	sCenterClubLabelMgr.GetPlayerClubRemarkInfo(pChr);
	return true;
}

// CMSG_CLUB_ADDREMARK = 0x211D,			// 设置玩家备注信息
bool SERVER_DECL script_world_process_club_setplayerremark(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 dest_pid;
	uint8 groupLabel_id;
	String strLabel;
	String strData;
	
	packet >> dest_pid >> groupLabel_id;
	GetPacketString<uint8>(&packet, strLabel);
	GetPacketString<uint16>(&packet, strData);
	
	Log.Debug("script_world_process_club_setplayerremark","char[%u] dest_pid[%u] groupLabel_id[%u] strLabel[%s] strData[%s]",
														pChr->getHandle(), dest_pid, groupLabel_id, strLabel.c_str(), strData.c_str());
	
	sCenterClubRemarkMgr.SetCenterClubRemarkInfo(pChr, dest_pid, groupLabel_id, strLabel, strData);
	return true;
}

// CMSG_CLUB_CHANGEGROUPNAME = 0x211E,		// 修改备注分组名称
bool SERVER_DECL script_world_process_club_changegrouplabelname(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint8 index;
	String strData;
	
	packet >> index;
	GetPacketString<uint8>(&packet, strData);
	
	Log.Debug("script_world_process_club_changegrouplabelname","char[%u] index[%u] strData[%s]", pChr->getHandle(), index, strData.c_str());
	sCenterClubLabelMgr.ChngeClubGroupLabel(pChr, index, strData);
	return true;
}

// CMSG_CLUB_ADDREMARKLABEL = 0x211F,		// 添加标签名称
bool SERVER_DECL script_world_process_club_addlabelname(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	String strData;
	GetPacketString<uint8>(&packet, strData);
	
	Log.Debug("script_world_process_club_addlabelname","char[%u] strData[%s]", pChr->getHandle(), strData.c_str());
	// sCenterClubLabelMgr.AddCenterClubRemarkLabel(pChr, strData);
	return true;
}

// CMSG_CLUB_REMOVEREMARKLABEL = 0x2120,	// 移除标签名称
bool SERVER_DECL script_world_process_club_removelavelname(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	String strData;
	GetPacketString<uint8>(&packet, strData);
	
	Log.Debug("script_world_process_club_removelavelname","char[%u] strData[%s]", pChr->getHandle(), strData.c_str());
	// sCenterClubLabelMgr.DeleteCenterClubRemarkLabel(pChr, strData);
	return true;
}

// CMSG_CLUB_REMOVEREMARKPLAYER = 0x2121,	// 移除备注玩家信息
bool SERVER_DECL script_world_process_club_removeremark(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 dest_pid;
	packet >> dest_pid;
	
	Log.Debug("script_world_process_club_removeremark","char[%u] dest_pid[%u]", pChr->getHandle(), dest_pid);
	sCenterClubRemarkMgr.RemoveCenterClubRemarkInfo(pChr, dest_pid);
	return true;
}

// CMSG_CLUB_PLAYERDETAILS = 0x2122,		// 俱乐部玩家详细信息
bool SERVER_DECL script_world_process_club_playerdetails(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 dest_pid;
	packet >> dest_pid;
	
	Log.Debug("script_world_process_club_playerdetails","char[%u] dest_pid[%u]", pChr->getHandle(), dest_pid);
	sCenterClubMgr.GetClubPlayerDetails(pChr, dest_pid);
	return true;
}

// CMSG_CLUB_CHOOSESEATBATTLELIST = 0x2123,	// 俱乐部选座房牌局列表
bool SERVER_DECL script_world_process_club_chooseseatbattlelist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	String parmas;
	GetPacketString<uint16>(&packet, parmas);
	
	Log.Debug("script_world_process_club_chooseseatbattlelist","char[%u] parmas[%s]", pChr->getHandle(), parmas.c_str());
	sCenterBattleMgr.GetClubChooseSeatBattleList(pChr, parmas);
	return true;
}

// CMSG_CLUB_BATTLEHISTORYLOG = 0x2124,		// 俱乐部历史战绩
bool SERVER_DECL script_world_process_club_battlehistorylogs(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	uint32 offset;
	uint16 num;
	
	packet >> club_id >> offset >> num;
	
	Log.Debug("script_world_process_club_battlehistorylogs","char[%u] club_id[%u]", pChr->getHandle(), club_id);
	sCenterBattleLogMgr.GetClubBattleLogs(pChr, club_id, offset, num);
	return true;
}

// CMSG_CLUB_REVIEWCOUNT = 0x2125,			// 俱乐部审核消息数量（用于显示审核旁边的红点）
bool SERVER_DECL script_world_process_club_reviewcount(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;		// 俱乐部ID
	uint8 type;			// 类型（1 审核加入 2 审核带入）
	packet >> club_id >> type;
	
	if(type == 1)
		sCenterClubMessageMgr.GetClubReviewMessagesCount(pChr, club_id);
	else if(type == 2)
		sCenterClubMessageMgr.GetClubTakeinMessagesCount(pChr, club_id);
	else if(type == 4)
		sCenterClubRoomMgr.RunningClubRoomCount(pChr, club_id);
	
	Log.Debug("script_world_process_club_reviewcount","char[%u] club_id[%u] type[%u]", pChr->getHandle(), club_id, type);
	return true;
}

// CMSG_CLUB_JOINMEESAGELIST = 0x2126,		// 俱乐部带入消息列表
bool SERVER_DECL script_world_process_club_joinmessagelist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;		// 俱乐部ID
	packet >> club_id;
	
	sCenterClubMessageMgr.GetClubReviewMessages(pChr, club_id);
	Log.Debug("script_world_process_club_joinmessagelist","char[%u] club_id[%u]", pChr->getHandle(), club_id);
	return true;
}

// CMSG_CLUB_EXITCOINSLOGS = 0x2127,		// 退分历史
bool SERVER_DECL script_world_process_club_exitcoinslogs(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint32 club_id;
	packet >> club_id;
	
	Log.Debug("script_world_process_club_exitcoinslogs","char[%u] club_id[%u]", pChr->getHandle(), club_id);
	sCenterClubLogMgr.GetExitCoinsLogs(pChr, club_id);
	return true;
}

// CMSG_CLUB_MTXCLUBINFO = 0x2129,			// 满天星俱乐部信息
bool SERVER_DECL script_world_process_club_mtxclubinfo(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint32 club_id;
	packet >> club_id;
	
	Log.Debug("script_world_process_club_mtxclubinfo","char[%u] club_id[%u]", pChr->getHandle(), club_id);
	sCenterClubMgr.GetMTFClubNormalInfo(pChr, club_id);
	return true;
}

// CMSG_CLUB_HISTORYCHENGJI = 0x212A,		// 俱乐部成绩总汇
bool SERVER_DECL script_world_process_club_historybattlechengji(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())
		return true;
	
	uint32 club_id;
	uint8 day;
	packet >> club_id >> day;
	
	Log.Debug("script_world_process_club_historybattlechengji","char[%u] club_id[%u] day[%u]", pChr->getHandle(), club_id, day);
	sCenterBattleLogMgr.GetClubBattleHistoryLogs(pChr, club_id, day);
	return true;
}

// CMSG_CLUB_CREATEMTF = 0x212B,			// 创建满天飞俱乐部
bool SERVER_DECL script_world_process_club_createmtf(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	String name;
	String desc;
	GetPacketString<uint8>(&packet, name);
	GetPacketString<uint16>(&packet, desc);
	
	name = ServerDatabase.EscapeString(name);
	desc = ServerDatabase.EscapeString(desc);
	
	Log.Debug("script_world_process_club_createmtf","char[%u] name[%s] desc[%s]", pChr->getHandle(), name.c_str(), desc.c_str());
	
	// 创建俱乐部
	sCenterClubMgr.CreateClubMTF(pChr, name, desc);
	return true;
}

//CMSG_CLUB_LIST = 0x212C,					// 请求俱乐部列表（名字/ID查询，自己的）
bool SERVER_DECL script_world_process_club_listinfomtf(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint8 type;
	String strData;
	
	packet >> type;
	GetPacketString<uint8>(&packet, strData);
	strData = ServerDatabase.EscapeString(strData);
	
	Log.Debug("script_world_process_club_listinfomtf","char[%u] type[%u] strData[%s]", pChr->getHandle(), type, strData.c_str());
	
	switch(type)
	{
	case enClubList_Name:	// 名字查询
		sCenterClubMgr.GetClubNormalInfoMTF(pChr, strData);
		break;
	case enClubList_Myself:	// 自己加入的
		sCenterClubMgr.GetSelfClubListMTF(pChr);
		break;
	default:
		break;
	}
	
	return true;
}

// CMSG_CLUB_CREATEFASTMODE = 0x212D,		// 创建快速开房配置
bool SERVER_DECL script_world_process_club_createfastmode(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	String strConfig;
	
	packet >> club_id;
	GetPacketString<uint16>(&packet, strConfig);
	
	Log.Debug("script_world_process_club_createfastmode","char[%u] club_id[%u] strConfig[%s]", pChr->getHandle(), club_id, strConfig.c_str());
	sCenterClubMgr.CreateFastCreateMode(pChr, club_id, strConfig);
	return true;
}

// CMSG_CLUB_DELETEFASTMODE = 0x212E,		// 删除快速开房配置
bool SERVER_DECL script_world_process_club_deletefastmode(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	uint8 index;
	packet >> club_id >> index;
	
	Log.Debug("script_world_process_club_deletefastmode","char[%u] club_id[%u] index[%u]", pChr->getHandle(), club_id, index);
	sCenterClubMgr.DeleteFastCreateMode(pChr, club_id, index);
	return true;
}

// CMSG_CLUB_GETFASTMODE = 0x212F,			// 获取快速开房配置
bool SERVER_DECL script_world_process_club_getfastmode(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint32 club_id;
	packet >> club_id;
	
	Log.Debug("script_world_process_club_getfastmode","char[%u] club_id[%u]", pChr->getHandle(), club_id);
	sCenterClubMgr.GetFastBuildMode(pChr, club_id);
	return true;
}

// CMSG_COMMON_CONFIGMISSIONLIST = 0x2200, 	// 配置任务列表
bool SERVER_DECL script_world_process_common_configmissionlist(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	UserPtr pUser = socket->getCurrentUser();
	if (pUser.isNull())
		return true;
	
	uint8 type;
	packet >> type;
	
	stCommonMission cm;
	sGameCommonMissionMgr.GetGameCommonMission(pUser->getUInt32Field("platform_id"), &cm);
	
	Log.Debug("script_world_process_common_configmissionlist","char[%u] type[%u]", pChr->getHandle(), type);
	if(sProtocolsMgr.CreateCommonConfigMissionListPacket(&packet, cm.data_list, type))
		socket->SendPacket(&packet);
	
	return true;
}

// CMSG_COMMON_CONFIGMISSIONGET = 0x2201,	// 领取配置任务
bool SERVER_DECL script_world_process_common_configmissionget(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint8 type;
	uint8 index;
	packet >> type >> index;
	Log.Debug("script_world_process_common_configmissionget","char[%u] type[%u] index[%u]", pChr->getHandle(), type, index);
	
	sGameCommonMissionMgr.GetBounty(pChr, type, index);
	return true;
}

// CMSG_COMMON_UPDATECONFIGMISSIONSTATUS = 0x2202,		// 任务状态更新
bool SERVER_DECL script_world_process_common_configmissionstatusupdate(ResourcePtr & sock,WorldPacket & packet)
{
	WSSocketPtr socket = sock;
	char cCode[14];
	if (!ChkSocketPacket(socket, packet, cCode))
		return true;
	
	CharPtr pChr = socket->getCurrentCharacter();
	if (pChr.isNull())  
		return true;
	
	uint8 type;
	uint8 sub_type;
	packet >> type >> sub_type;
	Log.Debug("script_world_process_common_configmissionget","char[%u] type[%u] sub_type[%u]", pChr->getHandle(), type, sub_type);
	
	// sGameCommonMissionMgr.GetBounty(pChr, type, index);
	return true;
}
